Dynamic runtime predicate pointer binding

Discussions related to Visual Prolog
kingchris
Active Member
Posts: 26
Joined: 26 Sep 2005 9:35

Dynamic runtime predicate pointer binding

Unread post by kingchris »

Pseudo Code.

Code: Select all

facts     predicate_pointer : pointer(string).   predicates     doNothing:(string).     writeToConsole:(string).     app_init().     doLotsOfWork().   clauses     app_init():-         if (debug_condition=true())             predicate_pointer := writeToConsole()         else             predicate_pointer := doNothing()     end if.       doLotsOfWork():-         repeat(),         LineVal = InStream:readLine(),           predicate_pointer(LineVal),           fail.  
This is a contrived example of the kind of thing that I wish to do.

Can I set up a fact or property or domain to allow what could be called runtime binding so that either the doNothing predicate gets called or writeToConsole gets called based on a runtime test.

Thanks for your trouble
User avatar
Thomas Linder Puls
VIP Member
Posts: 1176
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

You must have gone to a wrong school before ;-).

You should not use a "predicate pointer" you should use a predicate:

Code: Select all

domains     writer = (string String). facts     myWriter : writer.   predicates     doNothing:(string).     writeToConsole:(string).     app_init().     doLotsOfWork().   clauses     app_init():-         if debug_condition=true() then             myWriter := writeToConsole         else             myWriter := doNothing         end if.       doLotsOfWork():-         repeat(),         LineVal = InStream:readLine(),             myWriter(LineVal),         fail.
Also notice (other influence from your "wrong school") that you do not have to put parentheses around the test in an i-then-else, but you do have to write "then".
Regards Thomas Linder Puls
PDC
kingchris
Active Member
Posts: 26
Joined: 26 Sep 2005 9:35

Unread post by kingchris »

You are correct in your "wrong school" statements.

But please note that I did say Psuedo Code at the top. I and many other people on this forum, I am sure, program in multiple languages from F#, C#, C, C++, assembler, VB, Pascal etc. so its all gets very confusing. The latest PDC Prolog has introduced lots of things that you don't find in traditional Prolog. Hence I get very mixed up about what belongs in which language.

I was writing the essence of my problem. I personally get upset with people who post all of their code when asking a question. It becomes too much effort to read thorough and try and help them. So when I post a question I try keep it simple.

Thanks for your prompt answer.
I will code it up now into my program.
Cheers
User avatar
Thomas Linder Puls
VIP Member
Posts: 1176
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

No problem :-).

I hope it solves your problem.
Regards Thomas Linder Puls
PDC
Post Reply