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
"B" 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"
== "A"

>> value = "B"
== false

>> find value "B"
== none

So lets recap - ANY will stop evaluation as soon as it encounters a FALSE
evaluation.
                       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
TRUE.

Lets rewrite your function:

testfunc: func [option][
    either any [
       find option "A"
       find option "B"
       ][
       switch option

            "A" [print "A"]
            "B" [print "B"]
       ]
    ][
        print "C"
    ]
]
>> testfunc "A"
A
>> testfunc "B"
B
>> Testfunc "C"
C
>> Testfunc "D"
C

I hope this helps.

Paul Tretter





----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, February 17, 2001 1:44 PM
Subject: [REBOL] Re: "else" with 'switch


> Getting closer. But how come...
>
> >> testfunc "B"
> C
>
> Why doesn't 'switch work within 'either?
>
> testfunc: func [option][
>     either option = any [("A")("B")][
>         switch option [
>             "A" [print "A"]
>             "B" [print "B"]
>         ]
>     ][
>         print "C"
>     ]
> ]
>
> -Ryan
>
> >I'm trying to develop else-like logic using 'switch...
> >
> >testfunc: func [option][
> >    switch option [
> >        "A" [print "A"]
> >        "B" [print "B"]
> >        (not (all ["A" "B"])) [print "C"]
> >    ]
> >]
> >
> >The above function doesn't work. Is there a way to get this to work?
> >
> >-Ryan
> >
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to