Home   Archive   Permalink



error? try [error? get/any :word]

undefined?: func [
     {determines, if a word is undefined}
     word [any-word!]
] [
     error? try [error? get/any :word]
]
    
Can the line "error? try [error? get/any :word]" refactored as "error? try [get/any :word]", that is to say that the second "error?" is redundant?
    


posted by:   limux     19-Nov-2010/3:23:29-8:00



It probably can for several reasons:
    
1. ERROR? is not useful inside the TRY block. ERROR? needs an error object passed to it, and it will not reach ERROR?, since the interpreter stops processing the block before that occurs.
    
2. GET/ANY will return anything, even unset!, so asking whether an error occurs here is not correct.
    
3. Generally, be careful that you are not invoking other errors that are unrelated to the question of whether a word is defined or not. Provoking errors to find if something is of a specific value can be misleading.
    
BTW:
    
value? 'word
    
does almost the same thing and is native.

posted by:   Henrik     19-Nov-2010/4:11:31-8:00