[REBOL] Re: "else" with 'switch
From: ptretter:norcom2000 at: 17-Feb-2001 15:26
The problem is that ANY will return on the first false value it finds during
evaluation. The core.pdf is a bit confusing here but my experience is that
if you ensure that the values you are evaluating are either true or none you
will be safe. In your case since you use an operator "=" for the evaluation
you will get either a true or false result. This means that if 'option is
then you will get "C" because it reads the evaluation as False as soon
as it compares to "A". Therefore use the find function instead of an
operator for this evaluation which will result in either none or true during
evaluation. For example:
>> value: "A"
>> value = "B"
>> find value "B"
So lets recap - ANY will stop evaluation as soon as it encounters a FALSE
ANY will continue evaluation as long as the result is
not FALSE this includes TRUE and NONE evaluations.
ANY will return or select the value that evaluates to
Lets rewrite your function:
testfunc: func [option][
either any [
find option "A"
find option "B"
"A" [print "A"]
"B" [print "B"]
>> testfunc "A"
>> testfunc "B"
>> Testfunc "C"
>> Testfunc "D"
I hope this helps.