prolog在读命令中输入未知变量

时间:2013-11-22 17:23:38

标签: prolog

我有:

byCar(auckland,hamilton).
byCar(hamilton,raglan).

travelSimple2:- write('Travel'),nl,
                write('From where '),read(From),
                write('To where '),read(To),
                write('Using (car/train/plane) '),nl,
                read(Transport),
                travel(From,To,Transport).   

travel(From,To,car):-byCar(From,To).
travel(From,To,car) :- travel(From,Step,car), travel(Step,To,car).

首先我问一个查询:

| ?- travel(auckland,raglan,X).

Prolog然后回答

X = car ;

但是当我问

| ?- travelSimple2.
Travel
From where |: auckland.
To where |: raglan.
Using (car/train/plane) 
|: X.

它回答了

yes

所以我的问题是如何使prolog答案(X = car)像第一个查询而不是是。 有可能这样做吗?我认为命令是相似的,但为什么答案是不同的。

1 个答案:

答案 0 :(得分:0)

我认为应该是

travelSimple2:- write('Travel'),nl,
                write('From where '),read(From),
                write('To where '),read(To),
                write('Using (car/train/plane) '),nl,
                travel(From,To,Transport),
                write(Transport),nl.