Page 1 of 1

Execute a predicate stored in a clause (or fact)

Posted: 7 Jul 2022 21:24
by Harrison Pratt
I was thinking about ways to reduce code complexity in some menu functions and I seem to recall that it might be possible to store menu actions in a clause (or fact) structure, something like this:

Code: Select all

class predicates     doAction : (integer SelectionIndex, predicate ExecuteSelection [out]) determ. clauses     doAction(1, one).     doAction(2, two).     doAction(_, oops).   class predicates % to be executed, dependent upon the input to doAction/2     one : ().     two : ().     oops : ().   clauses     one() :-         stdio::write("\n", 1).       two() :-         stdio::write("\n", 2).       oops() :-         stdio::write("\nOOPS!").   clauses     run() :-         N = 1,  % index of a menu selection         doAction(N, Pred),         nothing(Pred),         % What to do to execute 'Pred' here ???         !.     run() :-         nothing("FAILED").
Is something like this possible?

Re: Execute a predicate stored in a clause (or fact)

Posted: 8 Jul 2022 1:57
by Gukalov

Code: Select all

        Pred(),

Re: Execute a predicate stored in a clause (or fact)

Posted: 8 Jul 2022 10:55
by Harrison Pratt
Thanks!

The sound you hear is me doing a "face-palm"! :D

Re: Execute a predicate stored in a clause (or fact)

Posted: 8 Jul 2022 15:56
by Gukalov
Don't do it, please!!!
According the sound you can harm and damage an importent VIP Member!!! :shock: