author | Alan Dipert
<alan@dipert.org> 2020-01-30 00:37:36 UTC |
committer | Alan Dipert
<alan@dipert.org> 2020-01-30 00:37:36 UTC |
parent | c21267d1f86dcc09b2e646a8bdae6f6a4e5f6503 |
boot.lisp | +55 | -29 |
diff --git a/boot.lisp b/boot.lisp index e0dfb20..38d3644 100644 --- a/boot.lisp +++ b/boot.lisp @@ -31,28 +31,10 @@ (export 'export) -(defun %instanceof (obj ctor) - (jacl:%js "(~{} instanceof ~{})" obj ctor)) - -(defun %== (x y) - (jacl:%js "(~{} == ~{})" x y)) - -(defun %=== (x y) - (jacl:%js "(~{} === ~{})" x y)) - (export 'set) (defun set (symbol value) (%js "(~{}.value = ~{})" symbol value)) -(export 'defvar) -(defmacro defvar (symbol &optional (value nil value?)) - `(jacl:%progn - (jacl:%js "~{}.isSpecial = true" ',symbol) - (jacl:%if (jacl:%js "(((~{}.value === UNDEFINED) && ~{}) ? true : null)" ',symbol ,value?) - (cl:set ',symbol ,value) - nil) - ',symbol)) - (export 'let) (defmacro let (bindings &rest body) `(jacl:%let ,bindings ,@body)) @@ -61,26 +43,70 @@ (defmacro if (test true-form &optional else-form) `(jacl:%if ,test ,true-form ,else-form)) +(export 'progn) +(defmacro progn (&rest forms) + `(jacl:%progn ,@forms)) + +(export 'when) +(defmacro when (test &rest forms) + `(if ,test (progn ,@forms))) + +(export 'defvar) +(defmacro defvar (symbol &optional (value nil value?)) + `(progn + (jacl:%js "~{}.isSpecial = true" ',symbol) + (when (jacl:%js "(((~{}.value === UNDEFINED) && ~{}) ? true : null)" ',symbol ,value?) + (set ',symbol ,value)) + ',symbol)) + +(export 'eq) +(defun eq (x y) + (jacl:%js "~{} === ~{} ? true : null" x y)) + +(export 'null) +(defun null (x) (eq x nil)) + +(export 'not) +(defun not (x) (eq x nil)) + (export 'car) -(defun car (x) - (jacl:\. x |car|)) +(defun car (x) (jacl:\. x |car|)) (export 'cdr) -(defun cdr (x) - (jacl:\. x |cdr|)) +(defun cdr (x) (jacl:\. x |cdr|)) -(export 'numberp) -(defun numberp (x) - (jacl:%js "typeof ~{} === 'number'" x)) +(export 'caar) +(defun caar (x) (car (car x))) -(defvar *gensym-counter* 0) +(export 'cdar) +(defun cdar (x) (car (cdr x))) -;; TODO gensym -;; TODO or +(export 'cond) +(defmacro cond (&rest clauses) + (when clauses + `(if ,(caar clauses) + ,(cdar clauses) + (cond ,@(cdr clauses))))) + +(export 'numberp) +(defun numberp (x) + (jacl:%js "typeof ~{} === 'number' ? true : null" x)) (export 'stringp) (defun stringp (x) - (jacl:%js "(~{} instanceof LispString ? true : null)" x)) + (jacl:%js "~{} instanceof LispString ? true : null" x)) + +(export 'symbolp) +(defun symbolp (x) + (jacl:%js "~{} instanceof LispSymbol ? true : null" x)) + +(export 'tagbody) +(defmacro tagbody (&rest body) + `(jacl:%tagbody ,@body)) + +(export 'go) +(defmacro go (tag) + `(jacl:%go ,tag)) ;; Use COMMON-LISP from COMMON-LISP-USER and switch to ;; COMMON-LISP-USER