Вопрос

When I type this have this code:

?- Tuple = ((2, 4), (2, 4)).

It says:

Tuple = ((2, 4), 2, 4).

But I would want it to say:

Tuple = ((2, 4), (2, 4)).

How can I achieve that?

Это было полезно?

Решение

It is generally not a good idea to think of the comma-operator as making "tuples". Pairs (as in your example) are still ok, but as you noticed, the syntax can be confusing because it hides the structure: (1,(2,3)) is the same as (1,2,3) and the same as 1,2,3.

Once you try making triplets you get into real trouble, because (1,2,3) is indistinguishable from the nested pairs (1,(2,3)). That's of course because it really is a nested pair, not a flat structure.

It is better style to use a specific functor, let's say t/N. Then there is no ambiguity between t(1,2,3) and t(1,t(2,3)).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top