Compilation error "4:12: syntax error: . or operator expected after expression" / problems with defining dynamic in prolog
Compilation error "4:12: syntax error: . or operator expected after expression" / problems with defining dynamic in prolog
请帮忙。
我在 GNU 序言中遇到了这个编译错误,当我使用 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).
。
请帮忙。 我在 GNU 序言中遇到了这个编译错误,当我使用 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).
。