1
1
mirror of https://github.com/kanaka/mal.git synced 2024-10-27 22:58:00 +03:00

bbc-basic: Define 'cond' and 'or' macros at startup, completing step 8.

This commit is contained in:
Ben Harris 2019-04-30 22:52:12 +01:00
parent 0e159177ca
commit 938f8c023c

View File

@ -21,6 +21,8 @@ REM Initial forms to evaluate
RESTORE +0
DATA (def! not (fn* (a) (if a false true)))
DATA (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))
DATA (defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw "odd number of forms to cond")) (cons 'cond (rest (rest xs)))))))
DATA (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))
DATA ""
REPEAT
READ form$