Hi Tim,
> > I avoid it, since it's a bit too easy to accidentally use v
> > without checking it it's an unset! or not.
Suppose we have a CD function, intended to be used at the console,
whose job is to either change the current directory, or print the
current directory if a new one was not supplied:
cd: func [dir [any-type!]][
either value? 'dir [print ["change-dir to" dir]][print mold
what-dir]
]
So it behaves like this:
>> cd %somedir/
change-dir to somedir/
>> cd
%/D/Anton/Dev/Rebol/View/
Great in the console, but if you use such a function in a script,
then you have to watch out for accidentally taking a value:
>> cd do [{some long code that returns a value} 10 + 2]
change-dir to 12
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.
Anton.
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.