列表内部或外部的序言对有什么用
我在 SWI-PL 文档中多次遇到键值对,但无法获得有关它们的详细信息。这是序言中的标准内容还是只是 swi pl 的扩展? 主要在这里找到: http://www.swi-prolog.org/pldoc /doc_for?object=keysort/2 这里:http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%27A.3%27,swi%28%27/doc/Manual/assoc.html%27 %29%29
配对的形式例如是a-5,或者列表[a-5, b-7]。
如果它是标准的,使用它们是否有任何附加值?他们的兴趣是什么?提前致谢 :)
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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
能够使用 keysort/2 确实是选择对列表(使用 (-)/2)作为表示的常见原因。它也是一种方便、简短且可读的表示法,并且 (-)/2 已经是一个中缀运算符(是的,“标准”,因为它是由 Prolog ISO 标准规定的)。 (-)/2-对的使用当然不限于键值组合,其他示例包括 id-变量、变量-“它在术语中出现的次数”等等,无论您在何处表示二元关联。通常其他运算符更直观地表示此类关联,例如用变量=值(而不是变量值)来表示变量的绑定,或者用字符串+字符串来表示串联。
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.