[gambit-list] Determine if symbol is bound
Marc Feeley
feeley at iro.umontreal.ca
Fri May 20 10:52:58 EDT 2011
On 2011-05-20, at 10:40 AM, REPLeffect wrote:
> 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 ?
Try
(bound? 'mytest)
Marc
More information about the Gambit-list
mailing list