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

[REBOL] Re: a new switch-like flow-control function

From: lmecir:mbox:vol:cz at: 23-Dec-2003 16:59

Hi Alain,
>Here is a function for only 1 condition but 3 cases : if it can be >useful to anyone > >trif: func [ > >... > >; example: >print trif request "give an answer" ["yes"]["no"]["cancel"] > >by the way, >is it good that "not none" equals "true" ? > >Alain Goyé. >
yes, it is useful. The following improvement uses the [throw] attribute to make the behaviour of the function more standard with respect to Return: trif: func [ {Three case if} [throw] condition iftrue [block!] iffalse [block!] ifnone [block!] ] [ do either condition [ iftrue ] [ either none? condition [ ifnone ] [ iffalse ] ] ] ; example: f: does [trif request "give an answer" [return "yes"] [return "no"] [return "cancel"] "Shoudn't get here"] Merry Christmas -Ladislav