-
Notifications
You must be signed in to change notification settings - Fork 1
/
inter.metta
157 lines (125 loc) · 4.01 KB
/
inter.metta
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
; (convert-to-metta-file inter $_448720 index/inter.pl index/inter.metta)
(= (show-lists $Filter $Texts $Lists)
(show-lists $Filter $Texts 1 Nil $Lists))
; /* interaction */
(= (show-lists $Filter $Words $N $Text ()) True)
(= (show-lists $Filter Nil $N $Text (Cons $H $T))
(show-list $Filter $Text
(Cons $H $T)))
(= (show-lists $Filter (Cons $Word $Words) 1 $Text (:: $H))
(set-det)
(show-lists $Filter $Words 1 $Text $H))
(= (show-lists $Filter (Cons $Word $Words) $N $Text (Cons $H $T))
(append $Text
(:: $Word $N --- ) $NewText)
(show-lists $Filter $Words 1 $NewText $H)
(is $N1
(+ $N 1))
(show-lists $Filter
(Cons $Word $Words) $N1 $Text $T))
(= (show-list $Filter $Text $List)
(filter $List $Filter $Filtered)
(show-list $Text $Filtered))
(= (show-list $Text Nil)
( (set-det)
(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)
(det-if-then-else
(nths $List $Ns Nil $Sel) True
(det-if-then otherwise
(,
(write 'Wrong number! Try again.') nl
(choose-list $Text $List $Sel)))))
(= (nths $List all Nil $List)
(set-det))
(= (nths $In (- $A $A) $Tmp $Out)
(set-det)
(nths $In $A $Tmp $Out))
(= (nths $In (- $A $B) $Tmp $Out)
(set-det)
(< $A $B)
(is $A1
(+ $A 1))
(nths $In $A $Tmp $Tmp1)
(nths $In
(- $A1 $B) $Tmp1 $Out))
(= (nths $In (, $N $Ns) $Tmp $Out)
(set-det)
(nths $In $N $Tmp $Tmp1)
(nths $In $Ns $Tmp1 $Out))
;
; nths([],1,Tmp,[X|Tmp]):-!,
;
; write('Which one? '),read(X).
(= (nths (Cons $X $R) 1 $Tmp (Cons $X $Tmp))
(set-det))
(= (nths (Cons $X $R) $N $Tmp $Out)
(is $N1
(- $N 1))
(nths $R $N1 $Tmp $Out))
; (error
; (syntax-error operator_expected)
; (file index/inter.pl 56 6 1401))
; (error
; (syntax-error operator_expected)
; (file index/inter.pl 60 6 1499))
(= (choose-items $N Nil) nl)
; ; nl,write_list([' ',N,'. Other...']),
(= (choose-items $N (Cons $H $T))
(nl
(write-list (:: $N . $H))
(is $N1
(+ $N 1))
(choose-items $N1 $T)))
(= (display-list () ()) True)
(= (display-list (Cons $H $T) (Cons $DH $DT))
(det-if-then-else
(switched-on horn)
(displayhorn $H $DH)
(det-if-then otherwise
(display $H $DH)))
(display-list $T $DT))
(= (displayhorn $X $HX)
(horn $X $HX)
(set-det))
(= (displayhorn $X $X) True)
(= (prompt-read $Question $Answer)
(write-list (:: $Question ? ))
(read $Answer)
(det-if-then-else
(= $Answer stop) fail
(det-if-then otherwise True)))
(= (yesno $Question)
(write-list $Question)
(read $Answer)
(det-if-then-else
(= $Answer yes) True
(det-if-then-else
(= $Answer no) fail
(det-if-then otherwise
(,
(call $Answer)
(yesno $Question))))))
; (error
; (syntax-error operator_expected)
; (file index/inter.pl 96 4 2236))
(= (write-debug $Message)
( (switched-on debug)
(write | )
(write-list $Message) nl))
(= (write-list $List)
(flatten $List $FList)
(write-list1 $FList))
(= (write-list1 ()) True)
(= (write-list1 (Cons $H $T))
(write $H)
(write-list1 $T))
(= quit abort)