]> Repositorios git - scryer-prolog.git/commitdiff
assign responsibility for emitting dif goal to the first variable of the left-hand...
authorMark Thom <[email protected]>
Wed, 22 Feb 2023 03:53:13 +0000 (20:53 -0700)
committerMark Thom <[email protected]>
Wed, 22 Feb 2023 17:28:29 +0000 (10:28 -0700)
src/lib/dif.pl

index 33e3e44b83bbdaa48d59a9cf13ef74cd78e29e3d..a59052ac5ca9569e02795988a7d0bd60b9635f89 100644 (file)
@@ -40,9 +40,6 @@ verify_attributes(Var, Value, Goals) :-
     ;   Goals = []
     ).
 
-% Probably the world's worst dif/2 implementation. I'm open to
-% suggestions for improvement.
-
 %% dif(?X, ?Y).
 %
 % True iff X and Y are different terms. Unlike `\=/2`, `dif/2` is more declarative because if X and Y can
@@ -69,12 +66,16 @@ dif(X, Y) :-
         )
     ).
 
-gather_dif_goals([]) --> [].
-gather_dif_goals([(X \== Y) | Goals]) -->
-    [dif:dif(X, Y)],
-    gather_dif_goals(Goals).
+gather_dif_goals(_, []) --> [].
+gather_dif_goals(V, [(X \== Y) | Goals]) -->
+    (  { term_variables(X, [V0 | _]),
+         V == V0 } ->
+       [dif:dif(X, Y)]
+    ;  []
+    ),
+    gather_dif_goals(V, Goals).
 
 attribute_goals(X) -->
     { get_atts(X, +dif(Goals)) },
-    gather_dif_goals(Goals),
+    gather_dif_goals(X, Goals),
     { put_atts(X, -dif(_)) }.