From d83e611d58441f546babd1d742926c191d416e58 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 16 Jul 2017 15:26:04 -0700 Subject: global environment accessors can now create bindings. The accessors symbol-value, symbol-function and symbol-macro can now be used to store a value to nonexistent bindings, which brings those bindings into existence. * share/txr/stdlib/place.tl (sys:ge-fun-getter-setter, sys:get-vb): Don't throw exceptions for nonexistent binding lookups: create and return the bindings instead. For methods, use static-slot-ensure rather than static-slot-set. Thus new methods can be defined by setting to a (meth ...) place. * txr.1: Doc updated. --- share/txr/stdlib/place.tl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'share') diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index 63d855a9..5b22e589 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -809,20 +809,18 @@ (:postinit (cons (op struct-get-postinitfun struct) (op struct-set-postinitfun struct))) (t (cons (op static-slot struct slot) - (op static-slot-set struct slot)))) + (op static-slot-ensure struct slot)))) :)) ((type sym) (if (eq type 'macro) - (let ((cell (gethash sys:top-mb sym))) - (unless cell - (sys:eval-err "unbound macro ~s" sym)) + (let ((cell (or (gethash sys:top-mb sym) + (sethash sys:top-mb sym (cons sym nil))))) (cons (op cdr) (op sys:rplacd cell))) :)) (else - (let ((cell (gethash sys:top-fb sym))) - (unless cell - (sys:eval-err "unbound function ~s" sym)) + (let ((cell (or (gethash sys:top-fb sym) + (sethash sys:top-fb sym (cons sym nil))))) (cons (op cdr) (op sys:rplacd cell)))))) @@ -856,7 +854,7 @@ (defun sys:get-vb (sym) (or (gethash sys:top-vb sym) - (sys:eval-err "unbound variable ~s" sym))) + (sethash sys:top-vb sym (cons sym nil)))) (defplace (symbol-value sym-expr) body (getter setter -- cgit v1.2.3