变量未声明
我的功能可以从列表中获取第一个项目,并检查该项目是否是几个项目之一,可以相应地执行一些功能,并在列表上的下一个项目上递归执行。
我的麻烦是,在第6行中,变量不再定义为列表的第一项,我很难弄清楚原因。
我刚开始与KBSS合作,如果我的语言不正确,请原谅我。
1 f(L) :-
2 [F|Ls] = L,
3 (
4 (F = value1 -> ...);
5 (F = value2 -> ...)
6 ) -> f(Ls); format('~w is not a valid action', [F]).
I have a function that takes the first item from a list, and checks if that item is one of several items, executes some functions accordingly and recursively executes on the next items on the list.
My trouble is that in line 6, the variable instantiated as the first item of the list is no longer defined, and I have trouble figuring out why.
I just started working with KBSs' so forgive me if my language is incorrect.
1 f(L) :-
2 [F|Ls] = L,
3 (
4 (F = value1 -> ...);
5 (F = value2 -> ...)
6 ) -> f(Ls); format('~w is not a valid action', [F]).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编译代码后,询问以下查询:
如您所见,统一是条件的一部分。因此,当条件失败时,统一为 undone ,转动
f
a 单变量。要解决问题,请按以下方式格式化代码:
After compiling your code, ask the following query:
As you can see, the unification is part of the condition. Thus, when condition fails, the unification is undone, turning
F
a single variable.To solve the problem, format the code as follows:
- >/2用法的示例:
结果:swi -promog:
Example of ->/2 usage:
Result in swi-prolog: