10 | 10 |
--------------------
|
11 | 11 |
|
12 | 12 |
| 5
|
13 | |
= Int 5
|
|
13 |
= 5
|
14 | 14 |
|
15 | 15 |
| +6+9+
|
16 | |
= Int 15
|
|
16 |
= 15
|
17 | 17 |
|
18 | 18 |
| +1+*7*-8-1-*+
|
19 | |
= Int 50
|
|
19 |
= 50
|
20 | 20 |
|
21 | 21 |
String expressions.
|
22 | 22 |
-------------------
|
23 | 23 |
|
|
24 |
| ~$Hello, world!$
|
|
25 |
= ~$Hello, world!$
|
|
26 |
|
24 | 27 |
| &~$Shoes are $&&~~&~$4.99 a pair$&&
|
25 | |
= Str "Shoes are $4.99 a pair"
|
|
28 |
= ~"Shoes are $4.99 a pair"
|
26 | 29 |
|
27 | 30 |
List expressions.
|
28 | 31 |
-----------------
|
29 | 32 |
|
30 | 33 |
| [1,2,3]
|
31 | |
= Cons (Int 1) (Cons (Int 2) (Cons (Int 3) Null))
|
|
34 |
= [1,2,3]
|
32 | 35 |
|
33 | 36 |
| [1,2|3]
|
34 | |
= Cons (Int 1) (Cons (Int 2) (Int 3))
|
|
37 |
= [1,2|3]
|
35 | 38 |
|
36 | 39 |
| <[1,2|3]<abort<
|
37 | |
= Int 1
|
|
40 |
= 1
|
38 | 41 |
|
39 | 42 |
| <1<abort<
|
40 | |
= Abort
|
|
43 |
= abort
|
41 | 44 |
|
42 | 45 |
| >[1,2|3]>abort>
|
43 | |
= Cons (Int 2) (Int 3)
|
|
46 |
= [2|3]
|
44 | 47 |
|
45 | 48 |
| >1>null>
|
46 | |
= Null
|
|
49 |
= null
|
47 | 50 |
|
48 | 51 |
| <,1,2,<null<
|
49 | |
= Int 1
|
|
52 |
= 1
|
50 | 53 |
|
51 | 54 |
| >,1,2,>null>
|
52 | |
= Int 2
|
|
55 |
= 2
|
53 | 56 |
|
54 | 57 |
| ,1,,2,3,,
|
55 | |
= Cons (Int 1) (Cons (Int 2) (Int 3))
|
|
58 |
= [1,2|3]
|
56 | 59 |
|
57 | 60 |
| ;[1,2];[3];
|
58 | |
= Cons (Int 1) (Cons (Int 2) (Cons (Int 3) Null))
|
|
61 |
= [1,2,3]
|
59 | 62 |
|
60 | 63 |
| ;[1,2];3;
|
61 | |
= Cons (Int 1) (Cons (Int 2) (Int 3))
|
|
64 |
= [1,2|3]
|
62 | 65 |
|
63 | 66 |
| ;null;null;
|
64 | |
= Null
|
|
67 |
= null
|
65 | 68 |
|
66 | 69 |
| ;[1];null;
|
67 | |
= Cons (Int 1) Null
|
|
70 |
= [1]
|
68 | 71 |
|
69 | 72 |
| ;null;[1];
|
70 | |
= Cons (Int 1) Null
|
|
73 |
= [1]
|
71 | 74 |
|
72 | 75 |
Labels and gotos.
|
73 | 76 |
-----------------
|
74 | 77 |
|
75 | 78 |
| :A:goto$A$
|
76 | |
= Label "A" (Goto "A")
|
|
79 |
= :A:goto $A$
|
77 | 80 |
|
78 | 81 |
Foreach expressions.
|
79 | 82 |
--------------------
|
80 | 83 |
|
81 | 84 |
| foreach $n$=[7,2,3] with $a$=0 be +$a$+$n$+ else be abort
|
82 | |
= Int 12
|
|
85 |
= 12
|
83 | 86 |
|
84 | 87 |
| foreach $n$=null with $a$=0 be +$a$+$n$+ else be abort
|
85 | |
= Abort
|
|
88 |
= abort
|
86 | 89 |
|
87 | 90 |
| foreach $n$=[1,2,3] with $a$=null be ,$n$,$a$, else be null
|
88 | |
= Cons (Int 3) (Cons (Int 2) (Cons (Int 1) Null))
|
|
91 |
= [3,2,1]
|
89 | 92 |
|
90 | 93 |
This is how boolean expressions can be built with `foreach`es.
|
91 | 94 |
We take `null` to mean **false** and `[1]` to mean **true**.
|
|
93 | 96 |
Boolean NOT.
|
94 | 97 |
|
95 | 98 |
| foreach $n$=null with $a$=null be null else be [1]
|
96 | |
= Cons (Int 1) Null
|
|
99 |
= [1]
|
97 | 100 |
|
98 | 101 |
| foreach $n$=[1] with $a$=null be null else be [1]
|
99 | |
= Null
|
|
102 |
= null
|
100 | 103 |
|
101 | 104 |
Boolean OR.
|
102 | 105 |
|
103 | 106 |
| foreach $n$=;[1];[1]; with $a$=[1] be $a$ else be null
|
104 | |
= Cons (Int 1) Null
|
|
107 |
= [1]
|
105 | 108 |
|
106 | 109 |
| foreach $n$=;null;[1]; with $a$=[1] be $a$ else be null
|
107 | |
= Cons (Int 1) Null
|
|
110 |
= [1]
|
108 | 111 |
|
109 | 112 |
| foreach $n$=;[1];null; with $a$=[1] be $a$ else be null
|
110 | |
= Cons (Int 1) Null
|
|
113 |
= [1]
|
111 | 114 |
|
112 | 115 |
| foreach $n$=;null;null; with $a$=[1] be $a$ else be null
|
113 | |
= Null
|
|
116 |
= null
|
114 | 117 |
|
115 | 118 |
Boolean AND.
|
116 | 119 |
|
|
118 | 121 |
| foreach $m$=$a$ with $b$=null be [1]
|
119 | 122 |
| else be null
|
120 | 123 |
| else be null
|
121 | |
= Cons (Int 1) Null
|
|
124 |
= [1]
|
122 | 125 |
|
123 | 126 |
| foreach $n$=null with $a$=[1] be
|
124 | 127 |
| foreach $m$=$a$ with $b$=null be [1]
|
125 | 128 |
| else be null
|
126 | 129 |
| else be null
|
127 | |
= Null
|
|
130 |
= null
|
128 | 131 |
|
129 | 132 |
| foreach $n$=[1] with $a$=null be
|
130 | 133 |
| foreach $m$=$a$ with $b$=null be [1]
|
131 | 134 |
| else be null
|
132 | 135 |
| else be null
|
133 | |
= Null
|
|
136 |
= null
|
134 | 137 |
|
135 | 138 |
| foreach $n$=null with $a$=null be
|
136 | 139 |
| foreach $m$=$a$ with $b$=null be [1]
|
137 | 140 |
| else be null
|
138 | 141 |
| else be null
|
139 | |
= Null
|
|
142 |
= null
|
140 | 143 |
|
141 | 144 |
Some list-processing-type things that you often see in functional
|
142 | 145 |
programming.
|
|
148 | 151 |
| ,$x$,$a$,
|
149 | 152 |
| else be
|
150 | 153 |
| null
|
151 | |
= Cons (Int 80) (Cons (Int 40) (Cons (Int 20) (Cons (Int 10) Null)))
|
|
154 |
= [80,40,20,10]
|
152 | 155 |
|
153 | 156 |
Find the length and the sum of a list of integers.
|
154 | 157 |
|
|
157 | 160 |
| ,+<$a$<0<+1+,+>$a$>0>+$x$+,
|
158 | 161 |
| else be
|
159 | 162 |
| null
|
160 | |
= Cons (Int 3) (Int 70)
|
|
163 |
= [3|70]
|
161 | 164 |
|
162 | 165 |
Take the first 3 elements from a list (in reverse order.)
|
163 | 166 |
|
|
170 | 173 |
| abort
|
171 | 174 |
| else be
|
172 | 175 |
| null
|
173 | |
= Cons (Cons (Int 40) (Cons (Int 20) (Cons (Int 10) Null))) (Cons (Int 1) Null)
|
|
176 |
= [[40,20,10],1]
|
174 | 177 |
|
175 | 178 |
Take the first 5 elements from a cyclic list.
|
176 | 179 |
|
|
183 | 186 |
| abort
|
184 | 187 |
| else be
|
185 | 188 |
| null
|
186 | |
= Cons (Cons (Int 10) (Cons (Int 20) (Cons (Int 10) (Cons (Int 20) (Cons (Int 10) Null))))) (Cons (Int 1) Null)
|
|
189 |
= [[10,20,10,20,10],1]
|
187 | 190 |
|
188 | 191 |
Macros.
|
189 | 192 |
-------
|
190 | 193 |
|
191 | 194 |
| {*[Five][5]}{Five}
|
192 | |
= Int 5
|
|
195 |
= 5
|
193 | 196 |
|
194 | 197 |
| {*[(A][1]}+{(A}+4+
|
195 | |
= Int 5
|
|
198 |
= 5
|
196 | 199 |
|
197 | 200 |
| {*[SQR][*{X}*{X}*]}{*[X][5]}{SQR}
|
198 | |
= Int 25
|
|
201 |
= 25
|
199 | 202 |
|
200 | 203 |
| {*[}][This is my comment!]}~${}}$
|
201 | |
= Str "This is my comment!"
|
|
204 |
= ~$This is my comment!$
|
202 | 205 |
|
203 | 206 |
| {*[Dave][3]}{*[Emily][4]}$Number of Macros Defined$
|
204 | |
= Int 2
|
|
207 |
= 2
|
205 | 208 |
|
206 | 209 |
| &~${$&~$*[S][T]}$&
|
207 | |
= Str "{*[S][T]}"
|
|
210 |
= ~${*[S][T]}$
|
208 | 211 |
|
209 | 212 |
| &~${$&~$S}$&
|
210 | |
= Str "{S}"
|
|
213 |
= ~${S}$
|
211 | 214 |
|
212 | 215 |
| %&~${$&~$*[S][T]}$&%&~${$&~$S}$&%
|
213 | |
= Str "T"
|
|
216 |
= ~$T$
|