简体   繁体   English

SICStus Prolog中的create_mutable / 2

[英]create_mutable/2 in SICStus Prolog

The SICStus Prolog manual page on mutable terms states that: 可变术语的SICStus Prolog手册页指出:

[...] the effect of unifying two mutables is undefined . [...]统一两个mutable的效果是不确定的

Then, why does create_mutable(data,x) fail? 那么,为什么create_mutable(data,x)会失败?

Shouldn't that rather raise an uninstantiation_error ? 不应该提出一个uninstantiation_error吗?

I cannot think of a situation when above case is not an unintentional programming error ( X vs x )... please help! 当上述情况不是无意的编程错误( X vs x )时,我想不出这种情况......请帮忙!

The short answer to "Why does create_mutable/2 not throw an exception when output unification fails?" 简单回答“为什么create_mutable/2在输出统一失败时不会抛出异常?” is just: Because this was how it was done when the feature was added to SICStus Prolog, and no one has made a strong case for changing this. 只是:因为这是将功能添加到SICStus Prolog时的工作方式,并且没有人提出改变这一点的强有力的理由。

One important "difference between the stream created by open/4 and the mutable term created by create_mutable/2 " is that open/4 has side-effects that are not undone if the output-unification of the call to open/4 fails. open/4创建的流与create_mutable/2创建的可变术语之间的一个重要区别是open/4具有如果对open/4的调用的输出统一失败则不会撤消的副作用。

In this sense, create_mutable/2 is somewhat more like is/2 which also just quietly fails if the output argument is some non-numeric non-variable term, eg in x is 3+4 . 从这个意义上说, create_mutable/2有点像is/2 ,如果输出参数是一些非数字非变量项,例如在x is 3+4 ,它也会悄然失败。 This seems to be the common, and traditional, way of handling output arguments in Prolog. 这似乎是在Prolog中处理输出参数的常见且传统的方式。

I agree that a non-variable as second argument is most likely a programming error. 我同意非变量作为第二个参数很可能是编程错误。 The next version of the SICStus IDE, SPIDER , will warn for this (as it already does for is/2 ). 下一版本的SICStus IDE SPIDER将对此发出警告(就像它已经为is/2 )。

None of this, nor the example in the question, seems directly related to the cited documentation "[...] the effect of unifying two mutables [...]". 这一点以及问题中的例子似乎与所引用的文件“[......]统一两个变量[...]的效果”直接相关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM