@@ -2,24 +2,31 @@ MiniLisp with REPL
22==================
33
44Foreword by N. Janin:
5- This is my attempt at making Rui Ueyama (rui314)'s MiniLisp slightly more user friendly and powerful.
6- Not being limited by the 1000 lines challenge, I've added a few basic primitives
5+ This is my attempt at making Rui Ueyama (rui314)'s MiniLisp slightly more user friendly
6+ and powerful.
7+ Not being limited by the 1000 lines challenge, I've added a number of basic primitives
78to the original program, while trying to keep the goal of simplicity and conciseness.
8- The whole program compiles to less than 100 kb without debugging symbols and should be able to run on low powered devices.
99
10+ The whole program compiles to less than 100 kb without debugging symbols and should be
11+ able to run on low powered devices.
12+
13+ The whole program compiles to less than 100 kb and should be able to run on low powered devices.
1014The added primitives:
1115* strings
12- * operators >, >=, <=, or, and, not,
16+ * predicates >, >=, <=, or, and, not,
17+
1318* functions length, reverse, progn, load.
14- This has the side effect of being much faster as well, since all these primitives are compiled
15- instead of being interpreted.
19+
20+ This has the side effect of being much faster as well, since all these primitives are
21+ compiled instead of being interpreted.
1622
1723Among the bells and whistles, I've added a REPL based on Justine Tunney (jart)'s bestline.
1824
1925In this version, instead of passing a file using pipes, you simply pass the files as command parameters :
2026./minilisp f1 f2 etc
2127
22- The files all share the same environment, so all the symbols, functions and macros defined in f1 can be reused in the following files.
28+ The files all share the same environment, so all the symbols, functions and macros defined
29+ in f1 can be reused in the following files.
2330
2431## Shortcuts
2532
@@ -170,12 +177,16 @@ car.
170177 (setcar cell 'x)
171178 cell ; -> (x . b)
172179
173- ` length ` and ` reverse ` operate on a whole list. They can also operate on their arguments.
180+ ` length ` and ` reverse ` operate on a whole list or a string. They can also operate on their
181+ arguments when their number is > 1.
182+
183+ (length '(1 2 3)) ; -> 3
184+ (length 1 2 t) ; -> 3
185+ (length "1 2 3") ; -> 5
174186
175- (length '(1 2 3)) ; -> 3
176- (length 1 2 t) ; -> 3
177- (reverse '(a b c)) ; -> (c b a)
178- (reverse '(a) b c) ; -> (c b (a))
187+ (reverse '(a b c)) ; -> (c b a)
188+ (reverse "1234") ; -> "4321"
189+ (reverse '((a) b "c") ; -> ("c" b (a))
179190
180191### Numeric operators
181192
@@ -207,7 +218,7 @@ the second.
207218 (< 3 3) ; -> ()
208219 (< 4 3) ; -> ()
209220
210- The other comparison operators ` > ` , ` <= ` , ` >= ` work in a similar fashion.
221+ The other numerical predicates ` > ` , ` <= ` , ` >= ` work in a similar fashion.
211222
212223` and ` takes two or more arguments, evaluates them, and returns the last argument
213224that returns true, if all the arguments return true, or () otherwise.
@@ -224,10 +235,10 @@ that returns true.
224235 (or () ()) ; -> ()
225236 (or) ; -> ()
226237
227- NB : because all the arguments are evaluated, ` and ` and ` or ` do not operate like
228- their counterparts written in Lisp, as those stop evaluation at the first argument
229- that returns. If the arguments have side effects, this may affect the program
230- differently.
238+ Nota Bene : because all the arguments are evaluated, ` and ` and ` or ` do not operate
239+ like their counterparts written in Lisp, as those stop evaluation at the first
240+ argument that returns. If the arguments have side effects, this may affect the
241+ program differently.
231242
232243### Conditionals
233244
@@ -247,12 +258,11 @@ exhaustion error.
247258
248259### Imperative programming
249260
250- ` progn ` executes several expressions consecutively .
261+ ` ( progn expr expr ...) ` executes several expressions in sequence .
251262
252- (progn (print 'I 'own)
253- (defun add(x y)(+ x y)
254- (println (add 3 7) 'cents))) ; -> I own
255- 10 cents
263+ (progn (print "I own ")
264+ (defun add(x y)(+ x y))
265+ (println (add 3 7) " cents")) ; -> prints "I own 10 cents"
256266
257267### Equivalence test operators
258268
@@ -269,7 +279,7 @@ contents but actually different are considered to not be the same by `eq`.
269279
270280` string-concat ` concatenates strings.
271281
272- (string-concat) ; -> ""
282+ (string-concat) ; -> ""
273283 (string-concat "A" "B" "C" "D") ; -> "ABCD"
274284
275285` symbol->string ` turns a symbol into a string.
@@ -285,8 +295,9 @@ contents but actually different are considered to not be the same by `eq`.
285295
286296` print ` prints a given object to the standard output.
287297
288- (print 3) ; prints "3"
289- (print '(hello world)) ; prints "(hello world)"
298+ (print 3) ; -> "3"
299+ (print '(hello world)) ; -> "(hello world)"
300+ (print "hello" "world") ; -> "hello world"
290301
291302` println ` does the same, adding a return at the end.
292303
@@ -345,12 +356,21 @@ is not defined.
345356 (define val (+ 3 5))
346357 (setq val (+ val 1)) ; increment "val"
347358
348- ### system functions
359+ ### Introspection
360+
361+ ` atom ` returns () if the argument is a cell, t otherwise.
362+
363+ (atom '(a b)) ; -> ()
364+ (atom "") ; -> t
365+ (atom ()) ; -> t
366+
367+ ### System functions
349368` load ` loads a Lisp file and evaluates all its content, adding it to the environment.
350369
351- (load 'example/nqueens.lisp) -> run the file and store its evaluated functions and macros
370+ (load "example/nqueens.lisp") -> run the file and store its evaluated functions
371+ and macros
352372
353- ` exit ` quits the interpreter and returns integer passed as parameter.
373+ ` exit ` quits the interpreter and returns the integer passed as parameter.
354374
355375 (exit 0) -> quit with success
356376
0 commit comments