-
Notifications
You must be signed in to change notification settings - Fork 1
/
inter.pl
executable file
·110 lines (95 loc) · 2.42 KB
/
inter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* interaction */
show_lists(Filter,Texts,Lists):-
show_lists(Filter,Texts,1,[],Lists).
show_lists(Filter,Words,N,Text,[]).
show_lists(Filter,[],N,Text,[H|T]):-
show_list(Filter,Text,[H|T]).
show_lists(Filter,[Word|Words],1,Text,[H]):-!,
show_lists(Filter,Words,1,Text,H).
show_lists(Filter,[Word|Words],N,Text,[H|T]):-
append(Text,[Word,N,' --- '],NewText),
show_lists(Filter,Words,1,NewText,H),
N1 is N+1,
show_lists(Filter,[Word|Words],N1,Text,T).
show_list(Filter,Text,List):-
filter(List,Filter,Filtered),
show_list(Text,Filtered).
show_list(Text,[]):- !,
write_list(['There are no ',Text,'.']),nl.
show_list(Text,List):-
write_list([Text,':']),
display_list(List,List1),
show_items(List1),nl.
choose_list(Text,List,Sel):-
display_list(List,List1),
choose_items(1,List1),
write_list([Text,'? ']),
read(Ns),
( nths(List,Ns,[],Sel) -> true
; otherwise -> write('Wrong number! Try again.'),nl,
choose_list(Text,List,Sel)
).
nths(List,all,[],List):-!.
nths(In,(A-A),Tmp,Out):-!,
nths(In,A,Tmp,Out).
nths(In,(A-B),Tmp,Out):-!,
A<B,A1 is A+1,
nths(In,A,Tmp,Tmp1),
nths(In,(A1-B),Tmp1,Out).
nths(In,(N,Ns),Tmp,Out):-!,
nths(In,N,Tmp,Tmp1),
nths(In,Ns,Tmp1,Out).
% nths([],1,Tmp,[X|Tmp]):-!,
% write('Which one? '),read(X).
nths([X|R],1,Tmp,[X|Tmp]):-!.
nths([X|R],N,Tmp,Out):-
N1 is N-1,
nths(R,N1,Tmp,Out).
show_items([]):-
( switched_on(horn) -> true
; not switched_on(horn) -> nl
).
show_items([H|T]):-
( switched_on(horn) -> portray_clause(H)
; not switched_on(horn) -> nl,write_list([' ',H])
),
show_items(T).
choose_items(N,[]):-
% nl,write_list([' ',N,'. Other...']),
nl.
choose_items(N,[H|T]):-
nl,write_list([' ',N,'. ',H]),
N1 is N+1,
choose_items(N1,T).
display_list([],[]).
display_list([H|T],[DH|DT]):-
( switched_on(horn) -> displayhorn(H,DH)
; otherwise -> display(H,DH)
),
display_list(T,DT).
displayhorn(X,HX):-
horn(X,HX),!.
displayhorn(X,X).
prompt_read(Question,Answer):-
write_list([Question,'? ']),read(Answer),
( Answer = stop -> fail
; otherwise -> true ).
yesno(Question):-
write_list(Question),read(Answer),
( Answer = yes -> true
; Answer = no -> fail
; otherwise -> call(Answer),yesno(Question)
).
write_debug(Message):-
not switched_on(debug).
write_debug(Message):-
switched_on(debug),
write(' | '),write_list(Message),nl.
write_list(List):-
flatten(List,FList),
write_list1(FList).
write_list1([]).
write_list1([H|T]):-
write(H),write_list1(T).
quit:-
abort.