Could someone please explain the strange syntax of the first line of the cryptarithmetic puzzle example in the CLP(FD) documentation: https://www.swi-prolog.org/pldoc/man?section=clpfd puzzle([S,E,N,D] + [M,O,R,E] = [M,O,N,E,Y]) :- ?
What is this + operator between two lists?
Is = here the unification operator?
OK, so since operator arguments are not typed, X + Y does not generate an error when X and Y are not numbers and = can be used as a term functor between two arguments that obviously can’t unify instead of as a unification predicate. Correct?
The way that this is usually explained is by using words like “homoiconic”. The way I understand it is that in Prolog, code and data have the same “shape”. A string like this:
A = B + C
is a Prolog term. Because both = and + are operators, this is parsed as the compound term =(A, +(B, C)). Wnen this term appears in a “data structure” slot, it is just a nested data structure. When the same term appears in the slot for a goal, it is evaluated as if it is code.
Here:
?- A = B + C.
A = B+C.
This was now in the slot for a goal. It was evaluated and the variable A was unified with the compound term +(A, B) which is printed by the top level as A+B because + is also defined as an operator.
But also:
?- A = 1, B = 2, C = 3, display(A = B + C).
=(1,+(2,3))
A = 1,
B = 2,
C = 3.
The last subgoal of the conjunction above is display(A = B + C). display/1 just prints on the top level its argument ignoring any operator definitions. If you decided to interpret this as a mathematical equation it is obviously wrong.