# Mystery Unification

**URL:** <https://swi-prolog.discourse.group/t/mystery-unification/929>\
**Category:** Help!\
**Created:** [July 7, 2019, 11:10am UTC](https://swi-prolog.discourse.group/t/mystery-unification/929 "2019-07-07T11:10:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcculloch](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mcculloch](https://swi-prolog.discourse.group/u/mcculloch)\
**Post date:** [July 7, 2019, 11:10am UTC](https://swi-prolog.discourse.group/t/mystery-unification/929/1 "2019-07-07T11:10:20Z")

</div>

I have this DCG:

```prolog
mdy(M,D,Y) --> integer(M),`/`,integer(D),`/`,integer(Y).

```

At first, I didn’t think it needed to be tested on its own, but I did it anyway. This is as expected:

```prolog
?- phrase(mdy(M,D,Y),`07/06/2019`,_).
M = 7,
D = 6,
Y = 2019.

```

When I do this I get an unexpected unification:

```prolog
?- phrase(mdy(M,D,Y),`07/07/2019`,_).
M = D, D = 7,
Y = 2019.

```

So far, I haven’t found anything wrong with it, but it does concern me that it makes a unification simply because two different variables just happen to equal the same value. Why would it do this?

Thanks,  
John

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 7, 2019, 11:27am UTC](https://swi-prolog.discourse.group/t/mystery-unification/929/2 "2019-07-07T11:27:06Z")

</div>

Writing a binding as

```
V1 = V2, V2 = V3, .... Vn-1 = Vn, Vn = <value>

```

is just (SWI-)Prolog’s way to say that two variables have exactly the same value (as in ==). In Prolog is generally not observable whether two terms are equal because they have been unified or simply because they happen to have the same value. Thus, `X = 7, X = Y` is internally exactly the same as `X = 7, Y = 7`.
