Remix.run Logo
YeGoblynQueenne 4 hours ago

See this:

  The original example in the last section was this:

  foo(A, B) :-
      \+ (A = B),
      A = 1,
      B = 2.

  foo(1, 2) returns true, so you'd expect f(A, B) to return A=1, B=2. But it returns false.

foo(A,B) fails because \+(A = B) fails, because A = B succeeds. That's because = is not an assignment but a unification, and in the query foo(A,B), A and B are variables, so they always unify.

In fact here I'm not sure whether the author expects = to work as an assignment or an equality. In \+(A = B) they seem to expect it to work as an equality, but in A = 1, B = 2, they seem to expect it to work as an assignment. It is neither.

I appreciate unification is confusing and takes effort to get one's head around, but note that the author is selling a book titled LOGIC FOR PROGR∀MMERS (in small caps) so they should really try to understand what the damn heck this logic programming stuff is all about. The book is $30.

dwattttt 3 hours ago | parent [-]

The author also wrote in the same article:

> This is also why you can't just write A = B+1: that unifies A with the compound term +(B, 1)