在Prolog中使用write谓词时出错

时间:2017-02-17 02:00:10

标签: prolog

我正在探索Prolog中的写谓词,但它有时表现不同。我确实经历了some posts,但我无法发现这个问题。

谓词:

explore_write_predicate(InputList,Index):-
   TempIndex is Index+1,
   select(Element,InputList,TempList),
   write(TempIndex).

查询:

explore_write_predicate([1,2,3,4],1).

结果:

2
true

上面的代码工作正常但是当我向写谓词添加一个参数(元素)时,它会给出错误。

谓词:

explore_write_predicate(InputList,Index):-
   TempIndex is Index+1,
   select(Element,InputList,TempList),
   write(TempIndex,Element).

查询:

   explore_write_predicate([1,2,3,4],1).

错误:

No permission to call sandboxed `write(_1132,_1134)'
Reachable from:
      explore_write_predicate(A,B)
      swish_trace:swish_call(explore_write_predicate([1,2,3,4],1))
      '$swish wrapper'(explore_write_predicate([1,2,3,4],1),A)

请帮助我为什么会出现这种异常现象。 P.S我也看到了写入的文档,但无法从中得到很多。 非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您的错误有两方面:

首先,您似乎使用SWISH作为首选解释器,这会锁定许多输入/输出方法(包括tab/1write/2get_single_char/1put/1等),因此您将无法使用它们。

其次,write/2需要一个流作为其第一个参数,第二个参数将写入其中 - 如注释中所述,写入多个内容要么将项目作为列表传递,要么使用多个写入。

相关问题