post-scarcity/lisp/defun.lisp
2021-07-25 17:02:28 +01:00

36 lines
664 B
Common Lisp

(set! list (lambda l l))
(set! symbolp (lambda (x) (equal (type x) "SYMB")))
(set! defun!
(nlambda
form
(cond ((symbolp (car form))
(set (car form) (apply 'lambda (cdr form))))
(t nil))))
(set! defun!
(nlambda
form
(eval (list 'set! (car form) (cons 'lambda (cdr form))))))
(defun! square (x) (* x x))
(set! defsp!
(nlambda
form
(cond (symbolp (car form))
(set! (car form) (apply nlambda (cdr form))))))
(defsp! cube (x) ((* x x x)))
(set! p 5)
(square 5) ;; should work
(square p) ;; should work
(cube 5) ;; should work
(cube p) ;; should fail: unbound symbol