[Ecls-list] unbound-variable handler

Dustin Long dlong at stevens.edu
Mon Jun 25 13:30:54 UTC 2007


That would be cell-error-name

(handler-bind
    ((unbound-variable
      (lambda (e)
        (format t "unbound var ~s~%" (cell-error-name e))
        (invoke-restart 'use-value nil))))
    (format t "value is [~s]~%" x))

cell-error-name also works in ECL, it's only the restart that doesn't. I 
really feel that deserves a patch. Not sure I'll have time to look into 
it myself, though.

Dustin

Dean O'Connor wrote:
>
>
> Hi Dunstin,
>
> Don't spose you have any idea how to print the name of the symbol that 
> was unbound ???
>
> (handler-bind
>        ((unbound-variable
>            (lambda (e)
>                (cl:when (not *quit-on-error*)
>                    (log-msg "#ERROR# Variable '" ???? "' not 
> initialised")
>                    (invoke-restart 'use-value nil)))))
>                     ....
>
> cheers
> deano
>
>
> Dustin Long wrote:
>> That's interesting....
>>
>> This works in clisp:
>>
>> (handler-bind ((unbound-variable (lambda (e) (invoke-restart 
>> 'use-value nil)))) (format t "value is [~s]~%" x))
>>
>> but not in ECL. Does anyone know if unbound-variable is supposed to 
>> establish the use-value restart? Or is that optional and 
>> implementation dependent? I can't find any information about the 
>> portability of such things.
>>
>> Dustin
>>
>> Dean O'Connor wrote:
>>> thanks a lot. That got me much further. This exits cleanly, but I 
>>> need it to continue executing the nested expressions, using value 
>>> NIL for the unbound variable.
>>>
>>> The aim was that if a scripts said something like:
>>>
>>>     (when VAR1
>>>           (print "yep"))
>>>
>>> Then if VAR1 was never bound by a SETQ or whatever, then VAR1's 
>>> value would simply returned as NIL (by a handler) instead of 
>>> entering debug.
>>>
>>> I am trying to RTFM to see if I can sort of continue, but if anyone 
>>> has the answer handy, I would much appreciate it.
>>>
>>> cheers
>>> deano
>>>
>>>
>>> Pierre THIERRY wrote:
>>>  
>>>> Scribit Dean O'Connor dies 19/06/2007 hora 03:03:
>>>>     
>>>>> I am trying to setup a handler to catch "unbound-variable".
>>>>>           
>>>> The thing is, if I understand the condition system correctly, you need
>>>> to setup a restart around the expression that might be unbound:
>>>>
>>>> (handler-bind
>>>>     ((unbound-variable (lambda (c)
>>>>              (declare (ignore c))
>>>>              (invoke-restart 'use-nil))))
>>>>   (not (restart-case
>>>>        not-yet-bound-variable
>>>>      (use-nil () nil))))
>>>>
>>>> Works in SBCL and ECL (yields t).
>>>>
>>>> Quickly,
>>>> Pierre
>>>>   
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> ------------------------------------------------------------------------- 
>>>>
>>>> This SF.net email is sponsored by DB2 Express
>>>> Download DB2 Express C - the FREE version of DB2 express and take
>>>> control of your XML. No limits. Just data. Click to get it now.
>>>> http://sourceforge.net/powerbar/db2/
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> _______________________________________________
>>>> Ecls-list mailing list
>>>> Ecls-list at lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/ecls-list
>>>>       
>>>
>>> ------------------------------------------------------------------------- 
>>>
>>> This SF.net email is sponsored by DB2 Express
>>> Download DB2 Express C - the FREE version of DB2 express and take
>>> control of your XML. No limits. Just data. Click to get it now.
>>> http://sourceforge.net/powerbar/db2/
>>> _______________________________________________
>>> Ecls-list mailing list
>>> Ecls-list at lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/ecls-list
>>>
>>>   
>>
>





More information about the ecl-devel mailing list