请帮忙。
我在GNU prolog中遇到此编译错误,当我使用SWISH时,它看起来像代码编译,但是当我尝试
?-current_room(X)。无论如何,它显示了错误(只是错误),所以我期望动态定义方式不正确。
% Rooms
:- dynamic current_room/1.
room(kitchen).
room(hall).
room(living_room).
room(dinning).
path(kitchen,dinning,n).
path(kitchen,hall2,e).
path(hall,living_room,s).
path(living_room,hall,n).
path(living_room,hall2,s).
path(living_room,dinning,w).
path(dinning,living_room,e).
path(dinning,kitchen,s).
path(hall2,living_room,n).
path(hall2,pantry,s).
path(pantry,hall2,n).
objects(couch).
in_room(living_room,couch).
route(room).
%(current_room,Destination, X).
%asserta(current_room(Destination)).
move(X) :- current_room(Z), path(Z,Y,X), retractall(my_pos(Z)), assert(my_pos(Y)).
n :- move(n).
s :- move(s).
w :- move(w).
e :- move(e).
start :- write('Type n/s/e/w'),nl, asserta(current_room(hall2)).
最佳答案
GNU序言具有不同的语法:- dynamic(current_room/1).
。
关于dynamic - 编译错误 “4:12: syntax error: . or operator expected after expression”/在序言中定义动态的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65860665/