Unification with STO detection

前端 未结 5 1540
野的像风
野的像风 2021-02-06 22:26

In ISO Prolog unification is defined only for those cases that are NSTO (not subject to occurs-check). The idea behind is to cover those cases of unifications that are mostly u

5条回答
  •  执念已碎
    2021-02-06 22:53

    In SWI-prolog:

    unify_sto(X,Y) :-
      \+ unify_with_occurs_check(X,Y),
      X = Y,
      !,
      writeln('Error: NSTO failure'),
      fail.
    
    unify_sto(X,Y) :-
      X = Y.
    

    gives the following results:

    [debug]  ?- unify_sto(X,s(X)).
    Error: NSTO failure
    false.
    
    [debug]  ?- unify_sto(X,a).
    X = a.
    
    [debug]  ?- unify_sto(b,a).
    false.
    

提交回复
热议问题