Question

I encountered several times Key-Value pairs in the SWI-PL doc but couldn't get a good info about them. Is this something standard in prolog or is it just a swi pl only extension ? Mainly found here : http://www.swi-prolog.org/pldoc/doc_for?object=keysort/2 and here : http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%27A.3%27,swi%28%27/doc/Manual/assoc.html%27%29%29

The form of the pairs is a-5 for example, or in a list [a-5, b-7].

And if it is standard, is there any added value to use those ? What is their interest ? Thanks in advance :)

Was it helpful?

Solution

Being able to use keysort/2 is indeed a common reason for choosing list of pairs (with (-)/2) as a representation. It's also a convenient, short and readable notation, and (-)/2 is already an infix operator (yes, "standard" in that it is prescribed by the Prolog ISO standard). The use of (-)/2-pairs is of course not restricted to key-value combinations, other examples include id-variable, variable-"number of its occurrences in a term", and so on, wherever you represent a binary association. Often other operators are more intuitive to represent such associations, such as variable=value (instead of variable-value) to represent a binding of a variable, or string+string to represent a concatenation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top