post-scarcity/lisp/defun.lisp
Simon Brooke e41ae1aa8b OK, big win: the oblist is now a hashmap, and it works. I have clear ideas now
about how to implement namespaces. There are probably regressions in this, but
progress nevertheless!
2026-02-03 17:20:55 +00:00

33 lines
638 B
Common Lisp

(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