Surprising result with equals dot dot

My favorite demonstration about the pitfalls of comma lists (as seen somewhere on the internets):

?- [A, B] = [A, B, C].
false. % of course

?- (A, B) = (A, B, C).
B =  (B, C). % WAT?

Coming from a language that has “tuples” this second query should come as a nasty surprise. It also shows why comma lists are not tuples in the widely accepted meaning of the word “tuple”.

And of course [] (the empty list) is a thing while () (the empty tuple?) is not a thing, as you mention.

Both Python (hugely popular) and Haskell (hugely popular in some circles) have tuples that look like (a, b); and Prolog accepts this construct, and it seems to work. The end result is that you see a lot of Prolog code that uses those, some of it apparently coming from people teaching Prolog to other people, within the safe space of educational institutions.

4 Likes