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
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.