Jon Wilson <[EMAIL PROTECTED]> writes:

> (define-macro (dyn-set! var val)
>                `(begin (if (not (defined? (quote ,var)))
>                          (primitive-eval `(define ,(quote ,var) #f)))
>                        (set! ,var ,val)))
>
> (defined? 'undefined-symbol) ; => #f
> ;(set! undefined-symbol #t)  Gives an error.
> (dyn-set! undefined-symbol #t) ; No error.
> (defined? 'undefined-symbol) ; => #t

I think this mostly does what you want, but

- isn't ,(quote xxx) equivalent to just xxx?

- as you kind of said, it will go wrong if ,var is defined locally:
  defined? will be #f for a local variable, so a top-level variable
  with the same name will be created, but the set! will then set the
  local variable.

Regards,
    Neil



_______________________________________________
Guile-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/guile-user

Reply via email to