From: Iqbal Ansari Date: Sun, 21 Aug 2016 14:52:09 +0000 (+0530) Subject: Implement or and cond macros, completes step 8 X-Git-Url: https://git.hcoop.net/jackhill/mal.git/commitdiff_plain/07b4ed9fa733c01ed14a82cefdb4cd221dbe0e1b Implement or and cond macros, completes step 8 --- diff --git a/common_lisp/step8_macros.lisp b/common_lisp/step8_macros.lisp index c3228211..da2b1835 100644 --- a/common_lisp/step8_macros.lisp +++ b/common_lisp/step8_macros.lisp @@ -211,6 +211,8 @@ (rep "(def! not (fn* (a) (if a false true)))") (rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") (rep "(def! *ARGV* (list))") +(rep "(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)))))))") +(rep "(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))))))))") (defun readline (prompt &optional (in-stream *standard-input*) (out-stream *standard-output*)) (format out-stream prompt)