# Don't understand syntax of clpfd cryptarithmetic puzzle example

**URL:** <https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730>\
**Category:** Help!\
**Tags:** clpfd\
**Created:** [January 9, 2020, 10:59pm UTC](https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730 "2020-01-09T22:59:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DamienDeville](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@DamienDeville](https://swi-prolog.discourse.group/u/DamienDeville)\
**Post date:** [January 9, 2020, 10:59pm UTC](https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730/1 "2020-01-09T22:59:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [January 9, 2020, 11:05pm UTC](https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730/2 "2020-01-09T23:05:36Z")

</div>

```prolog
?- display(a + b = c).
=(+(a,b),c)
true.

```

Long story short, it is just a nested term. `+` and `=` are defined as operators which is why you can write it like this. See the [documentation for op/3](https://www.swi-prolog.org/pldoc/doc_for?object=op/3).

---

<div class="post-metadata">

**Author:** ![pmoura](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/pmoura/32/11_2.png) [@pmoura](https://swi-prolog.discourse.group/u/pmoura)\
**Post date:** [January 9, 2020, 11:06pm UTC](https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730/3 "2020-01-09T23:06:19Z")

</div>

This may help:

```prolog
?- write_canonical([S,E,N,D] + [M,O,R,E] = [M,O,N,E,Y]).
=(+([_,A,D,_],[B,C,_,A]),[B,C,D,A,_])
true.

```

I.e. `[S,E,N,D] + [M,O,R,E] = [M,O,N,E,Y]` is just a compound term written to take advantage of operator definitions.

---

<div class="post-metadata">

**Author:** ![DamienDeville](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@DamienDeville](https://swi-prolog.discourse.group/u/DamienDeville)\
**Post date:** [January 10, 2020, 12:44am UTC](https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730/4 "2020-01-10T00:44:45Z")

</div>

Thanks.

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?

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [January 10, 2020, 8:00am UTC](https://swi-prolog.discourse.group/t/dont-understand-syntax-of-clpfd-cryptarithmetic-puzzle-example/1730/5 "2020-01-10T08:00:26Z")

</div>

Yes, 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:

```prolog
?- 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:

```prolog
?- 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.

Are you more confused now? You are welcome!
