[gambit-list] Determine if symbol is bound

REPLeffect repleffect at gmail.com
Fri May 20 10:40:48 EDT 2011


On Mon, May 9, 2011 at 8:55 AM, Marc Feeley <feeley at iro.umontreal.ca> wrote:
>
> On 2011-05-08, at 4:30 PM, William James wrote:
>
>> 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))
>
> This is the official way to test is a global variable is bound:
>
> (define (bound? name)
>  (not (##unbound? (##global-var-ref (##make-global-var name)))))
>
> Marc
>

I tried this running this in the interpreter, and got the following result:

> (define (bound? name)
      (not (##unbound? (##global-var-ref (##make-global-var name)))))
> (bound? mytest)
*** ERROR IN (console)@1779.9 -- Unbound variable: mytest
1>

Am I missing something?  'mytest' was undefined, obviously, but
shouldn't bound? have returned #f ?



More information about the Gambit-list mailing list