【发布时间】:2022-11-14 04:57:37
【问题描述】:
我正在尝试在 Prolog 中写入 N 次文件。我想出了这个解决方案:
response(M,Out,N):-
write('How do you feel ?'),
open('output.txt',write,Out),
read(M),
write(Out,M),
close(Out),
response(M,Out,S),
S is N-1.
response(M,Out,0).
基本思想是从键盘读取情绪并将其写入名为output.txt 的文件中。它给了我这个错误:
ERROR: Uninstantiated argument expected, found <stream>(0x60000311fb00) (stream-argument)
ERROR: In:
ERROR: [12] open('/Users/dylan/Desktop/output.txt',write,<stream>(0x60000311fb00))
ERROR: [11] response(sad,<stream>(0x60000311fb00),_10234) at /Users/dylan/Desktop/suggestsong.pl:14
ERROR: [10] response(sad,<stream>(0x60000311fb00),3) at /Users/dylan/Desktop/suggestsong.pl:18
ERROR: [9] toplevel_call(user:user: ...) at /Applications/SWI- Prolog.app/Contents/swipl/boot/toplevel.pl:1158
Exception: (11) response(sad, <stream>(0x60000311fb00), _9654) ? creep
Exception: (10) response(_9306, _9308, 3) ? creep
没有循环的谓词工作正常,但它只是一次阅读,不适合目的。
可以请人帮助我吗?谢谢你们。
【问题讨论】:
-
使用例如
trace看看发生了什么 - swi-prolog.org/pldoc/man?section=debugger
标签: prolog