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