Prolog 写函数的问题

Issues with Prolog's write function

下面的代码应该输出:

A solution is: 
The farmer takes the Goat from west of the river to east 
The farmer crosses the river from east to west 
The farmer takes the cabbage from west of the river to east 
The farmer takes the Goat from east of the river to west 
The farmer takes the Wolf from west of the river to east 
The farmer crosses the river from east to west 
The farmer takes the Goat from west of the river to east 
No

但是我收到以下错误,我似乎无法修复它。如果有人能指引我正确的方向,我将不胜感激。

?- solve.
A solution is:
ERROR: write_move/2: Undefined procedure: write/4
ERROR:   However, there are definitions for:
ERROR:         write/1
ERROR:         writeq/1
ERROR:         write/2
ERROR:         writeq/2
   Exception: (10) write('The farmer takes the Goat from ', west, ' of the river to ', east) ? 

代码:(部分)

write_move(state(X,W,G,C),state(Y,W,G,C)):- !,

write('The farmer crosses the river from ',X,' to ',Y), nl.

write_move(state(X,X,G,C),state(Y,Y,G,C)):- !,

write('The farmer takes the Wolf from ',X,' of the river to ',Y), nl.

write_move(state(X,W,X,C),state(Y,W,Y,C)):- !,

write('The farmer takes the Goat from ',X,' of the river to ',Y),nl.

write_move(state(X,W,G,X),state(Y,W,G,Y)):- !,

write('The farmer takes the cabbage from ',X,' of the river to ',Y),nl.

如果有人感兴趣,此代码的提示是:

描述:一位农民带着他的山羊、狼和卷心菜来到一条他们想渡过的河边。有一艘船,但它只能容纳两个人,而农夫是唯一会划船的人。如果山羊和卷心菜同时上船,卷心菜就会被吃掉。同样,如果没有农夫,狼和山羊在一起,山羊就会被吃掉。设计一系列的河流渡口,以便所有相关人员安全渡河。

write/1 只接受一个参数。 未定义过程 write/4 表示没有定义 write/4write 接受 4 个参数)。错误消息表明 write/1 存在。

替代:

write('The farmer takes the Wolf from ',X,' of the river to ',Y), nl.

您可以执行以下操作之一:

write('The farmer takes the Wolf from '),
write(X),
write(' of the river to '),
write(Y), nl.

或者...

format('The farmer takes the Wolf from ~w to ~w~n', [X, Y]).

或者(在 SWI Prolog 中)...

writef('The farmer crosses the river from %w to %w\n', [X, Y]).

可能还有其他几种方法...:)