begin:-
go,
initialise. % drive predicate
begin:-
write('Sorry cannot help'),nl,nl.
go:-
write('Below is the list of the current toys available within the
store.'),nl,nl,nl,nl,
loop_through_list([car, football, action_men, train_tracks, lego, football, bikes, control_car, drees_up, doll, bear, furbies, craft, doll_house]).
loop_through_list([Head|Tail]) :-
write(Head),
write(' '),
loop_through_list(Tail).
initialise:-
nl,nl,nl,nl,
tab(40),write('******************************************'),nl,
tab(40),write('*** TOY GENERATING SYSTEM ***'),nl,
tab(40),write('******************************************'),nl,nl,
write('Please answer the following questions'),
write(' y (yes) or n (no).'),nl,nl, nl, nl.
这里的问题是go:-
和initialise:-
在单独使用时会分开工作,但在放在一起时却不能。所有nl
s都存在问题吗?
答案 0 :(得分:2)
问题是go/0
无法正常工作。当它打印列表时,它最后会失败,这意味着执行将在之后停止。因此,当您运行begin/0
时,initialize/0
将永远无法运行。
要解决此问题,您需要为loop_through_list/0
添加基本案例:
loop_through_list([]).
loop_through_list([Head|Tail]) :-
write(Head),
write(' '),
loop_through_list(Tail).
作为旁注,“print_list”将是loop_through_list/0