What is the use of prolog pairs in or outside lists

柔情痞子 提交于 2019-12-14 01:17:07

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/8052892/what-is-the-use-of-prolog-pairs-in-or-outside-lists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!