3

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 :)

false
  • 10,264
  • 13
  • 101
  • 209
m09
  • 7,490
  • 3
  • 31
  • 58

1 Answers1

7

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.

mat
  • 40,498
  • 3
  • 51
  • 78
  • 3
    Ok, so that's what I presumed, no added value, only a random operator linking two things. Thanks a lot for clearing this up! :) – m09 Nov 08 '11 at 21:47