Wednesday, January 19, 2005, 12:17:54 PM, PeterWAWood wrote:
> I have started to question whether it is best to use Rebol's > automatic type checking of parameters or not when designing > functions. > If the type checking is used, calling a function with an incorrect type of > value causes a script error, eg: > >> a: func [b [date!]] [print b] > >> a 12345 > ** Script Error: a expected b argument of type: date > ** Near: a 12345 > However, if you don't use the built-in type checking, you can return a none! > value and give the caller the option (and responsibility) to deal with the > situation, eg: > >> a: func [b] [if type? b <> date! [return none]] > >> a 12345 > == none > Given that Rebol is not strongly typed, is the second of these > "idioms" the more appropriate? While the latter has obvious flaws when dealing with functions that may validly return 'none, I can see no advantages whatsoever. If the caller wants to deal with the situation, why not simply use 'try ? For example a: func [b [date!]] [print b] if error? try [ a 12345 ] [ print "uh oh!" ] -- Best regards, Andreas -- To unsubscribe from the list, just send an email to rebol-request at rebol.com with unsubscribe as the subject.
