Discussions related to Visual Prolog
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Execute a predicate stored in a clause (or fact)

Unread post 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?
User avatar
Gukalov
VIP Member
Posts: 62
Joined: 5 Oct 2011 15:16

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

Unread post by Gukalov »

Code: Select all

        Pred(),
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

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

Unread post by Harrison Pratt »

Thanks!

The sound you hear is me doing a "face-palm"! :D
User avatar
Gukalov
VIP Member
Posts: 62
Joined: 5 Oct 2011 15:16

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

Unread post by Gukalov »

Don't do it, please!!!
According the sound you can harm and damage an importent VIP Member!!! :shock:
Post Reply