* Anton Rolls <[EMAIL PROTECTED]> [051001 15:06]:
> Consider that the above line might be written by you in a script like this:
> 
>       cd
>       ;
>       ; some intervening comments like this might make the line above
>       ; and the line below look completely unrelated.
>       ;
>       do [{some long code that returns a value} 10 + 2]
>       
> which has the same output:
> 
>       change-dir to 12
> 
> A solution is to wrap in parens like this:
> 
>       >> (cd) do [{some long code that returns a value} 10 + 2]
>       %/D/Anton/Dev/Rebol/View/
>       == 12
> 
> But it doesn't help you to remember whether you need the parens or not.
> If you forget, you can have a confusing bug for while.
> So you always wrap in parens (no thought required), or only use parens when
> there can be a value afterwards (requires your careful attention).
> 
> It just makes things complicated, so that's why we generally avoid
> accepting unset! in function arguments.

  Good advice. In my case it simplifies things to use a function like
  this, but my approach would be to use it only inside of
  well-thought-out subroutines.
  With your advice well in mind. :-)

  Another approach could be best illustrated by some pythonesque pseudo-code:
  as in 
  try:
    t: print "this will generate an error with an id of: 'need-value"
  except NeedValueError:   ## python traps only the error you want to
                           ##  trapped
    return default-value
 (I love rebol, but python has some valuable error-trapping classes)
 ;; so we could do this with rebol: 
main: func[][
    t: print "hello"
    ]
dump-error: func[obj[object!]][
    if obj/id = 'need-value[
        print "handling a no value error"
        return ""
        ]
    ]
;; 
=========================================================================================
application: [; execution block
    print <pre>
    main
    ]
;;======================================================================================================
except: [dump-error disarm err ]
if error? set/any 'err try application except 

-- 
Tim Johnson <[EMAIL PROTECTED]>
      http://www.alaska-internet-solutions.com
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to