문제

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