Prolog is vs = with lists

与世无争的帅哥 提交于 2019-12-10 01:52:27

问题


Why does this fail L is [1,2,3,4], and this works: L = [1,2,3]?

But L is 1, and L = 1 both work the same.


回答1:


is should only be used when evaluating arithmetic operations on the right-hand side. i.e.:

X is 1 + 2 + 3

is/2 evaluates the right-hand structure as an arithmetic expression. If it is not a valid arithmetic expression or a number, is/2 fails. Otherwise, the number to which the arithmetic expression evaluted is unified with the [presumably] unbound left-hand value.



来源:https://stackoverflow.com/questions/1525282/prolog-is-vs-with-lists

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