# Possibly bad result in console for a triple of pairs

**URL:** <https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834>\
**Category:** General\
**Tags:** bug\
**Created:** [October 7, 2022, 3:48pm UTC](https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834 "2022-10-07T15:48:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vjktm](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/vjktm/32/4893_2.png) [@vjktm](https://swi-prolog.discourse.group/u/vjktm)\
**Post date:** [October 7, 2022, 3:48pm UTC](https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834/1 "2022-10-07T15:48:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kuniaki.mukai](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kuniaki.mukai](https://swi-prolog.discourse.group/u/kuniaki.mukai)\
**Post date:** [October 7, 2022, 4:25pm UTC](https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834/2 "2022-10-07T16:25:00Z")

</div>

> [@vjktm](#):
>
> 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 = (_, _),_

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.

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

```

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [October 7, 2022, 5:35pm UTC](https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834/3 "2022-10-07T17:35:03Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [October 7, 2022, 5:37pm UTC](https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834/4 "2022-10-07T17:37:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brebs](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@brebs](https://swi-prolog.discourse.group/u/brebs)\
**Post date:** [October 7, 2022, 6:32pm UTC](https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834/5 "2022-10-07T18:32:17Z")

</div>

Use a term name, for less confusion - [Surprising result with equals dot dot](https://swi-prolog.discourse.group/t/surprising-result-with-equals-dot-dot/4989)

---

<div class="post-metadata">

**Author:** ![vjktm](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/vjktm/32/4893_2.png) [@vjktm](https://swi-prolog.discourse.group/u/vjktm)\
**Post date:** [October 8, 2022, 2:23am UTC](https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834/6 "2022-10-08T02:23:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vjktm](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/vjktm/32/4893_2.png) [@vjktm](https://swi-prolog.discourse.group/u/vjktm)\
**Post date:** [October 8, 2022, 2:55am UTC](https://swi-prolog.discourse.group/t/possibly-bad-result-in-console-for-a-triple-of-pairs/5834/7 "2022-10-08T02:55:55Z")

</div>

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.
