[gambit-list] Determine if symbol is bound

Mikael mikael.rcv at gmail.com
Mon May 9 09:50:34 EDT 2011


Adrien - in addition to what you suggested he wants to define something in
case it's unbound.

What about, based on your macro

(define-macro (define/only-if-unbound var-name value)
  (if (not (symbol? var-name)) (error "Symbol expected"))
  `(define ,var-name (with-exception-catcher
                      (lambda (e) ,value)
                      (lambda () ,var-name))))


> (define xyz 1)
> (define/only-if-unbound xyz 2)
> xyz
1
> (define/only-if-unbound xyz2 123)
> (define/only-if-unbound xyz2 456)
> xyz2
123

Only use this kind of coding strategy if you have a really good reason to.

Mikael

2011/5/9 Adrien Piérard <pierarda at iro.umontreal.ca>

> What about this?
>
> (define-macro (bound? x)
>  `(with-exception-handler
>     (lambda (e) #f)
>     (lambda () (and ,x #t))))
>
> (pp (bound? x))
> (let ((y 3))
>  (pp (bound? y)))
>
>
> Cheers,
>
> P!
>
> 2011/5/9 William James <w_a_x_man at yahoo.com>:
> > How do you check to see if a symbol is already bound?
> > To be used in this fashion:
> >
> > (if (bound? x)
> >  (set! x 22)
> >  (define x 22))
> > _______________________________________________
> > Gambit-list mailing list
> > Gambit-list at iro.umontreal.ca
> > https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
> >
>
>
>
> --
> Français, English, 日本語, 한국어
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20110509/890b740c/attachment.htm>


More information about the Gambit-list mailing list