如何让程序继续下去?

时间:2017-12-19 00:21:37

标签: prolog

如何在menu1/0出现后让程序继续false

mylist([a,b,c]).
myprog(X) :- mylist(L), member(X, L).

go :- start_message,menu1.

start_message :- 
    write('This is a program.'),nl,
    write('Below are a list:'),nl,
    myprog(X), 
    write(X),nl, 
    fail.

menu1 :-
    nl,write('Select operation:'),nl,
    write('1. Input time'),nl,
    write('2. Exit program'),nl.

以下是我的观点:

go.
This is a program.
Below are a list:
a
b
c
false

2 个答案:

答案 0 :(得分:1)

你可以这样做

start_message :- 
    write('This is a program.'),nl,
    write('Below are a list:'),nl,
    ( myprog(X),
      write(X),nl, 
      fail
    ; true ).

现在myprog/1不能再成功,控制权转到true/0start_message/0成功。

答案 1 :(得分:0)

删除fail的最后一行中的start_message语句。