当用户添加项目然后显示列表时,程序将输出列表而不考虑用户添加的项目在我看来,项目并未真正添加。我需要你的帮助。而且..
%00:33 du bist toll!
:-dynamic item/1.
item([coffee,milk,chocolate,apple,juice]).
menu:-
nl, write("**SHOPPING LIST **"),nl,
write('d - Display all items.'), nl,
write('a - Add an item to the list.'), nl,
write('e - Exit.'),
write('-------------------------------'), nl,
write('Enter your choice: '),
read(X), check(X),(X=e;menu).
check(a):-
nl,
write('Enter the item you want to add to the shopping list'), nl,
%adding to list operations
read(I),
item(L),not(member(I,L)),
retract(item(L)),
assert(item([I|L])),
write('The item has been added').
check(d):-
nl,
item(L),
displayL(L).
displayL([]).
displayL([X|Y]):- write(X),nl, displayL(Y).
check(e):-.
item([coffee,milk,chocolate,apple,juice]).
menu:-
nl, write("**SHOPPING LIST **"),nl,
write('d - Display all items.'), nl,
write('a - Add an item to the list.'), nl,
write('e - Exit.'),
write('-------------------------------'), nl,
write('Enter your choice: '),
read(X), check(X),(X=e;menu).
check(a):-
nl,
write('Enter the item you want to add to the shopping list'), nl,
%adding to list operations
read(I),
item(L),not(member(I,L)),
retract(item(L)),
assert(item([I|L])),
write('The item has been added').
check(d):-
nl,
item(L),
displayL(L).
displayL([]).
displayL([X|Y]):- write(X),nl, displayL(Y).
check(e):-.