Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[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 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"
>> testfunc "B"
>> Testfunc "C"
>> Testfunc "D"
C I hope this helps. Paul Tretter