查阅文件时参数未充分实例化
Arguments not sufficiently instantiated when consulting file
我通过终端在 Mac 上 运行 SWI-Prolog。在终端中打开 swipl 后,我正在尝试通过编写通常的方式来访问 Atom 文件:
?- [hwk1-my_name].
swipl 没有可玩的知识库,而是给了我这个:
ERROR: Arguments are not sufficiently instantiated
我是 Prolog 的新手,我现在的程序只是我的教授提供的用于开始作业的复制粘贴代码。这是否意味着错误可能是由于以下代码中的某些内容引起的,如果是,是什么原因导致的?这是提供给我的代码:
father(Dad, Child) :-
parent(Dad, Child),
male(Dad).
mother(Mom, Child) :-
parent(Mom, Child),
female(Mom).
had_a_child(Man, Woman) :-
father(Man, Child),
mother(Woman, Child).
sibling(Sibling1, Sibling2) :-
parent(Parent, Sibling1),
parent(Parent, Sibling2),
Sibling1 \= Sibling2.
brother(Brother, Sib) :-
sibling(Brother, Sib),
male(Brother).
sister(Sister, Sib) :-
sibling(Sister, Sib),
female(Sister).
你的明显问题是文件名里面的-
。您使用的文本编辑器完全无关紧要。甚至令人困惑,因为 Prolog 的一种数据类型是 atom.
您有两个选择:
使用即使不加引号也是有效 Prolog atom 的文件名。这意味着它们不能以大写字母或数字开头,并且只能包含字母、数字和下划线 (_
)。然后,你的文件仍然可以有 .pl
扩展名,你可以像你一样查阅它:foo.pl
---> ?- [foo].
使用完整的文件名,包括扩展名,并用单引号括起来:foo-bar.baz
---> ?- ['foo-bar.baz'].
。正如您将看到的,您甚至不再需要 .pl
扩展。
每当您对 Prolog 看到的内容有疑问时,您可以尝试 write_canonical/1
:
?- write_canonical(hwk1-my_name).
-(hwk1, my_name)
true.
换句话说,Prolog 将 this 作为复合项 -/2
,原子 hwk1
和 my_name
作为第一个和第二个参数。
我通过终端在 Mac 上 运行 SWI-Prolog。在终端中打开 swipl 后,我正在尝试通过编写通常的方式来访问 Atom 文件:
?- [hwk1-my_name].
swipl 没有可玩的知识库,而是给了我这个:
ERROR: Arguments are not sufficiently instantiated
我是 Prolog 的新手,我现在的程序只是我的教授提供的用于开始作业的复制粘贴代码。这是否意味着错误可能是由于以下代码中的某些内容引起的,如果是,是什么原因导致的?这是提供给我的代码:
father(Dad, Child) :-
parent(Dad, Child),
male(Dad).
mother(Mom, Child) :-
parent(Mom, Child),
female(Mom).
had_a_child(Man, Woman) :-
father(Man, Child),
mother(Woman, Child).
sibling(Sibling1, Sibling2) :-
parent(Parent, Sibling1),
parent(Parent, Sibling2),
Sibling1 \= Sibling2.
brother(Brother, Sib) :-
sibling(Brother, Sib),
male(Brother).
sister(Sister, Sib) :-
sibling(Sister, Sib),
female(Sister).
你的明显问题是文件名里面的-
。您使用的文本编辑器完全无关紧要。甚至令人困惑,因为 Prolog 的一种数据类型是 atom.
您有两个选择:
使用即使不加引号也是有效 Prolog atom 的文件名。这意味着它们不能以大写字母或数字开头,并且只能包含字母、数字和下划线 (
_
)。然后,你的文件仍然可以有.pl
扩展名,你可以像你一样查阅它:foo.pl
--->?- [foo].
使用完整的文件名,包括扩展名,并用单引号括起来:
foo-bar.baz
--->?- ['foo-bar.baz'].
。正如您将看到的,您甚至不再需要.pl
扩展。
每当您对 Prolog 看到的内容有疑问时,您可以尝试 write_canonical/1
:
?- write_canonical(hwk1-my_name).
-(hwk1, my_name)
true.
换句话说,Prolog 将 this 作为复合项 -/2
,原子 hwk1
和 my_name
作为第一个和第二个参数。