Commit | Line | Data |
---|---|---|
60154d24 JM |
1 | # mal - Make a Lisp |
2 | ||
bcddc3e4 JM |
3 | ## Description |
4 | ||
5 | Mal is an interpreter for a subset of the Clojure programming | |
a816262a | 6 | language. Mal is implemented from scratch in 19 different languages: |
bcddc3e4 | 7 | |
edc3b064 | 8 | * Bash shell |
bcddc3e4 | 9 | * C |
edc3b064 JM |
10 | * C# |
11 | * Clojure | |
891c3f3b | 12 | * CoffeeScript |
1771ab50 | 13 | * Go |
bcddc3e4 | 14 | * Java |
d32f9b87 | 15 | * Javascript ([Online Demo](http://kanaka.github.io/mal)) |
bcddc3e4 JM |
16 | * GNU Make |
17 | * mal itself | |
6301e0b6 | 18 | * Perl |
edc3b064 JM |
19 | * PHP |
20 | * Postscript | |
21 | * Python | |
9b3362e8 | 22 | * R |
8adb0827 | 23 | * Ruby |
abdd56eb | 24 | * Rust |
821930db | 25 | * Scala |
ee7cd585 | 26 | * Visual Basic.NET |
bcddc3e4 JM |
27 | |
28 | ||
8d8679f2 | 29 | Mal is also a learning tool. Each implementation of mal is separated |
bcddc3e4 JM |
30 | into 11 incremental, self-contained (and testable) steps that |
31 | demonstrate core concepts of Lisp. The last step is capable of | |
32 | self-hosting (running the mal implemenation of mal). | |
33 | ||
34 | The mal (make a lisp) steps are: | |
35 | ||
36 | * step0_repl | |
37 | * step1_read_print | |
38 | * step2_eval | |
39 | * step3_env | |
40 | * step4_if_fn_do | |
41 | * step5_tco | |
42 | * step6_file | |
43 | * step7_quote | |
44 | * step8_macros | |
f41866db JM |
45 | * step9_try |
46 | * stepA_interop | |
bcddc3e4 JM |
47 | |
48 | ||
49 | Mal was presented publicly for the first time in a lightning talk at | |
50 | Clojure West 2014 (unfortunately there is no video). See | |
51 | mal/clojurewest2014.mal for the presentation that was given at the | |
52 | conference (yes the presentation is a mal program). | |
60154d24 JM |
53 | |
54 | ## Building/running implementations | |
55 | ||
bcddc3e4 | 56 | ### Bash 4 |
60154d24 JM |
57 | |
58 | ``` | |
59 | cd bash | |
60 | bash stepX_YYY.sh | |
61 | ``` | |
62 | ||
bcddc3e4 | 63 | ### C |
60154d24 | 64 | |
01c97316 JM |
65 | The C implementation of mal requires the following libraries (lib and |
66 | header packages): glib, libffi6 and either the libedit or GNU readline library. | |
54c75382 | 67 | |
60154d24 JM |
68 | ``` |
69 | cd c | |
70 | make | |
71 | ./stepX_YYY | |
72 | ``` | |
73 | ||
9b1563a3 | 74 | ### C# ### |
edc3b064 JM |
75 | |
76 | The C# implementation of mal has been tested on Linux using the Mono | |
77 | C# compiler (mcs) and the Mono runtime (version 2.10.8.1). Both are | |
78 | required to build and run the C# implementation. | |
79 | ||
80 | ``` | |
81 | cd cs | |
82 | make | |
ee7cd585 | 83 | mono ./stepX_YYY.exe |
edc3b064 JM |
84 | ``` |
85 | ||
86 | ||
bcddc3e4 | 87 | ### Clojure |
60154d24 JM |
88 | |
89 | ``` | |
90 | cd clojure | |
91 | lein with-profile +stepX trampoline run | |
92 | ``` | |
93 | ||
891c3f3b JM |
94 | ### CoffeeScript |
95 | ||
96 | ``` | |
97 | sudo npm install -g coffee-script | |
98 | cd coffee | |
99 | coffee ./stepX_YYY | |
100 | ``` | |
101 | ||
1771ab50 JM |
102 | ### Go |
103 | ||
104 | ``` | |
105 | cd go | |
106 | make | |
107 | ./stepX_YYY | |
108 | ``` | |
109 | ||
110 | ||
bcddc3e4 | 111 | ### Java 1.7 |
60154d24 | 112 | |
01c97316 JM |
113 | The Java implementation of mal requires maven2 to build. |
114 | ||
60154d24 JM |
115 | ``` |
116 | cd java | |
117 | mvn compile | |
118 | mvn -quiet exec:java -Dexec.mainClass=mal.stepX_YYY | |
119 | # OR | |
120 | mvn -quiet exec:java -Dexec.mainClass=mal.stepX_YYY -Dexec.args="CMDLINE_ARGS" | |
121 | ``` | |
122 | ||
bcddc3e4 | 123 | ### Javascript/Node |
60154d24 JM |
124 | |
125 | ``` | |
126 | cd js | |
54c75382 | 127 | npm update |
60154d24 JM |
128 | node stepX_YYY.js |
129 | ``` | |
130 | ||
bcddc3e4 | 131 | ### Mal |
60154d24 JM |
132 | |
133 | Running the mal implementation of mal involves running stepA of one of | |
134 | the other implementations and passing the mal step to run as a command | |
5d446bd8 | 135 | line argument. |
60154d24 JM |
136 | |
137 | ``` | |
138 | cd IMPL | |
139 | IMPL_STEPA_CMD ../mal/stepX_YYY.mal | |
140 | ||
141 | ``` | |
142 | ||
bcddc3e4 | 143 | ### GNU Make 3.81 |
60154d24 JM |
144 | |
145 | ``` | |
146 | cd make | |
147 | make -f stepX_YYY.mk | |
148 | ``` | |
149 | ||
9b1563a3 | 150 | ### Perl 5.8 |
9e5b2151 JM |
151 | |
152 | For readline line editing support, install Term::ReadLine::Perl or | |
153 | Term::ReadLine::Gnu from CPAN. | |
154 | ||
155 | ``` | |
156 | cd perl | |
157 | perl stepX_YYY.pl | |
158 | ``` | |
159 | ||
160 | ||
bcddc3e4 | 161 | ### PHP 5.3 |
60154d24 | 162 | |
01c97316 JM |
163 | The PHP implementation of mal requires the php command line interface |
164 | to run. | |
165 | ||
60154d24 JM |
166 | ``` |
167 | cd php | |
168 | php stepX_YYY.php | |
169 | ``` | |
170 | ||
bcddc3e4 | 171 | ### Postscript Level 2/3 |
60154d24 | 172 | |
01c97316 JM |
173 | The Postscript implementation of mal requires ghostscript to run. It |
174 | has been tested with ghostscript 9.10. | |
175 | ||
60154d24 JM |
176 | ``` |
177 | cd ps | |
fa64b741 | 178 | gs -q -dNODISPLAY -I./ stepX_YYY.ps |
60154d24 JM |
179 | ``` |
180 | ||
a05f7822 | 181 | ### Python (2 or 3) |
60154d24 JM |
182 | |
183 | ``` | |
184 | cd python | |
185 | python stepX_YYY.py | |
186 | ``` | |
8adb0827 | 187 | |
9b3362e8 JM |
188 | ### R |
189 | ||
190 | The R implementation of mal requires R (r-base-core) to run. | |
191 | ||
192 | ``` | |
193 | cd r | |
194 | make libs | |
195 | Rscript stepX_YYY.rb | |
196 | ``` | |
197 | ||
8adb0827 JM |
198 | ### Ruby (1.8) |
199 | ||
200 | ``` | |
201 | cd ruby | |
202 | ruby stepX_YYY.rb | |
203 | ``` | |
592eb5cf | 204 | |
abdd56eb JM |
205 | ### Rust (0.13) |
206 | ||
207 | The rust implementation of mal requires the rust compiler and build | |
208 | tool (cargo) to build. | |
209 | ||
210 | ``` | |
211 | cd rust | |
111dbaf1 JM |
212 | # Need patched pcre lib (should be temporary) |
213 | git clone https://github.com/kanaka/rust-pcre cadencemarseille-pcre | |
abdd56eb JM |
214 | cargo build |
215 | ./target/stepX_YYY | |
216 | ``` | |
217 | ||
821930db JM |
218 | ### Scala ### |
219 | ||
220 | Install scala and sbt (http://www.scala-sbt.org/0.13/tutorial/Installing-sbt-on-Linux.html): | |
221 | ||
222 | ``` | |
223 | cd scala | |
224 | sbt 'run-main stepX_YYY' | |
225 | # OR | |
226 | sbt compile | |
227 | scala -classpath target/scala*/classes stepX_YYY | |
228 | ``` | |
229 | ||
ee7cd585 JM |
230 | ### Visual Basic.NET ### |
231 | ||
232 | The VB.NET implementation of mal has been tested on Linux using the Mono | |
233 | VB compiler (vbnc) and the Mono runtime (version 2.10.8.1). Both are | |
234 | required to build and run the VB.NET implementation. | |
235 | ||
236 | ``` | |
237 | cd vb | |
238 | make | |
239 | mono ./stepX_YYY.exe | |
240 | ``` | |
241 | ||
242 | ||
243 | ||
592eb5cf JM |
244 | ## Running tests |
245 | ||
a816262a | 246 | The are nearly 500 generic Mal tests (for all implementations) in the |
592eb5cf JM |
247 | `tests/` directory. Each step has a corresponding test file containing |
248 | tests specific to that step. The `runtest.py` test harness uses | |
249 | pexpect to launch a Mal step implementation and then feeds the tests | |
250 | one at a time to the implementation and compares the output/return | |
251 | value to the expected output/return value. | |
252 | ||
253 | To simplify the process of running tests, a top level Makefile is | |
254 | provided with convenient test targets. | |
255 | ||
256 | * To run all the tests across all implementations (be prepared to wait): | |
257 | ||
258 | ``` | |
259 | make test | |
260 | ``` | |
261 | ||
262 | * To run all tests against a single implementation: | |
263 | ||
264 | ``` | |
265 | make test^IMPL | |
266 | ||
267 | # e.g. | |
268 | make test^clojure | |
269 | make test^js | |
270 | ``` | |
271 | ||
272 | * To run tests for a single step against all implementations: | |
273 | ||
274 | ``` | |
275 | make test^stepX | |
276 | ||
277 | # e.g. | |
278 | make test^step2 | |
279 | make test^step7 | |
280 | ``` | |
281 | ||
282 | * To run a specifc step against a single implementation: | |
283 | ||
284 | ``` | |
285 | make test^IMPL^stepX | |
286 | ||
287 | # e.g | |
288 | make test^ruby^step3 | |
289 | make test^ps^step4 | |
290 | ``` |