post-scarcity/lisp/defun.lisp
Simon Brooke 70376c6529 Careful debugging of the memory leak problem. At this stage,
stack frames for interpreted (but not primitive) functions appear not to be being
reclaimed, and the oblist doesn't seem to be being fully reclaimed.
2026-02-20 19:39:19 +00:00

33 lines
638 B
Common Lisp

(set! symbol? (lambda (x) (equal (type x) "SYMB")))
(set! defun!
(nlambda
form
(cond ((symbol? (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 (symbol? (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