DYNAMIC unification is possible Sort Of

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

DYNAMIC unification is possible Sort Of

Unread post by kingchris » 10 Jan 2016 13:56

No question here just something I found useful.

I asked a question a while back
Is DYNAMIC unification possible!

During some heavy prolog writing recently I have found the following works for me.

Code: Select all

predicates     unification:(integer) procedure.     unification_string:(string) procedure. clauses     unification_string(string1):-!,         stdio::write("4. Found ",string1,"\n").         unification_string(string2):-!,         stdio::write("5. Found ",string2,"\n").       unification_string(String):-!,         stdio::write("6. Found ",String,"\n").       unification(var1):-!,         stdio::write("1. Found ",var1,"\n").       unification(var2):-!,         stdio::write("2. Found ",var2,"\n").       unification(Var):-         stdio::write("3. Found ",Var,"\n").      test():-         unification(89),         unification(90),         unification(900),         unification(7890),         var2 := 7890,         unification(7890),         unification_string("Fred"),         unification_string("Bob"),         unification_string("Anywhere"),         string2:= "Anywhere",         unification_string("Anywhere").
  • 3. Found 89
    1. Found 90
    2. Found 900
    3. Found 7890
    2. Found 7890
    4. Found Fred
    5. Found Bob
    6. Found Anywhere
    5. Found Anywhere
A simple trick. By using a fact variable as our unification target then changing its value we can change what it finds.

This may be documented elsewhere but I have yet to come across it.

I find that it simplifies state machine parsing and a few other things for me.

Post Reply