Possibly bad result in console for a triple of pairs

Not sure if this a bug but I defined the following:
three_pairs(X,Y,Z, R):-
X =(,),
Y =(,),
Z =(,),
R = (X,Y,Z).
For the query:
three_pairs(,,,Result).
I got the following with out parenthesis around the last pair:
Result = ((
, ), (, ), , ).
I expected the following:
Result = ((
, ), (, ), (, )).
However, if I do:
three_pairs(
,
,
,(A,B,C)).
I get the following as I would expect:
A = (_, ),
B = (
, ),
C = (
, _).

So, is there a problem in the console result of:
three_pairs(,,_,Result).
?
Thanks,
viktim

I think queries below are related to your question. I could not explain well. For a long time my experience says that , (comma) , and | ( vertical bar) are something special when they are used as atoms. Thus I also am looking forward to clear answers to be posted by some experts for your questions.

?- write_canonical(',').
','
true.
?- write_canonical((,)).
ERROR: Syntax error: Operand expected, unquoted comma or bar found
ERROR: write_canonical(
ERROR: ** here **
ERROR: (,)) .

you should use code fences (i.e. three backtick) otherwise your code is pretty unreadable:

    three_pairs(X,Y,Z, R):-
        X =(_,_),
        Y =(_,_),
        Z =(_,_),
        R = (X,Y,Z).

OT: you can use the three dots menu and then the Edit Raw icon to get the Prolog code of the question

Use a term name, for less confusion - Surprising result with equals dot dot

Sorry, bad cut/paste from SWI-Prolog console.

Thank you everyone for your responses and links to related discussions. I now know a bit more about SWI-Prolog, pairs, comma lists and comma operator. I will name the pairs as it seems to be the recommended solution.

1 Like