Мой код в прологе отображается в обратном ожидаемом порядке. Вот код:Почему мой код пролога в обратном порядке?
room(homermargeroom, donuts).
room(homermargeroom, tv).
room(ensuite, nothing).
room(lisaroom, beer).
room(bartroom, donuts).
room(hallway, nothing).
room(bathroom, nothing).
room(maggieroom, nothing).
/* These are the locations where Bart, Lisa and Maggie are hiding */
hiding(bart, cupboard).
hiding(lisa, ensuite).
hiding(maggie, bathroom).
canHomerGet(Start, End, Item) :-
homermove(Start, End),
canTravelThrough(Start, Item),
canTravelThrough(End, Item),
write('Homer moves from '), write(Start), write(' to '), write(End), nl.
canHomerGet(Start, End, Item) :-
homermove(Start, Somewhere),
canTravelThrough(Somewhere, Item),
canHomerGet(Somewhere, End, Item),
write('Homer moves from '), write(Start), write(' to '), write(Somewhere), nl.
canTravelThrough(Somewhere, _Item) :-
room(Somewhere, nothing).
canTravelThrough(Somewhere, Item) :-
room(Somewhere, tv),
Item == portableTV.
canTravelThrough(Somewhere, Item) :-
room(Somewhere, donuts),
Item == nachos.
canTravelThrough(Somewhere, Item) :-
room(Somewhere, sistersinlaw),
Item == blindfold.
canTravelThrough(Somewhere, Item) :-
room(Somewhere, beer),
Item == margarita.
canHomerFind(Child, Item) :-
hiding(Child, Destination),
canHomerGet(garage, Destination, Item).
Здесь выход:
Гомер перемещается из фойе Купбоарда
Гомера перемещается из столовой в фойе
Гомер перемещается из кухни в столовой
Гомер перемещается из sidehall на кухню
Гомер перемещается из гаража в боковой проход
Как я это написал, я ожидаю, что это напечатает «Гомер движется из гаража в кулак», а затем распечатает этот список в обратном порядке. Любые предложения по устранению этого?
Вы уверены, что предоставили весь исходный код? Этот вывод создается с помощью какого запроса? –