Prolog (a,b,c,d) is a bad choice as it is a term ','(a, ','(b, ','(c,d))), which is not an array as what Python tuples are. Also () is illegal syntax. So, we represent tuples as -(a,b,c,d), exploiting Prolog’s common pair notation for the common binary tuples: a-b.
We had long discussions, but nobody came up with anything better … These things happen if you need to map data between languages.
That is a nested pair. The Python tuple (1,2,3) takes the Prolog shape -(1,2,3). There was a clear agreement that a tuple should map on a compound term and a lot of discussion about the functor name.
Yes, exactly. You also missed the 0-tuple and the singleton, so
- % or maybe -()
-(1)
-(1,2)
...
Interestingly, when I just search the wider internets for “list vs tuple” all top hits take me to Python-specific sources. This one for example:
Tuples are heterogeneous data structures (i.e., their entries have different meanings), while lists are homogeneous sequences. Tuples have structure, lists have order.
This proposal is not ideal but it looks really close, and it’s somewhat clean Prolog. The big discussion was about the name of the functor, not about the concept itself. Is there any potential problems with picking the -, since it is so overloaded with meaning? But then again, a Prolog pair 1-2 is supported by a few useful built-ins, although keysort/2 is can now be expressed in terms of sort/4 in SWI-Prolog so…