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

[REBOL] Re: Core 2.6 - Last minute requests - take your chance!

From: rotenca:telvia:it at: 5-Apr-2002 18:58

31) Some changes for switch: a) do :value instead of do value (for function! and parens! datatype) and do :case instead of do case (default) b) a new refinement /only, to permit multiple cases like this: switch/only 2 [1 2 3 [print "found"]] block! switch/only 2 reduce [1 2 3 does [print "found"]] function! a more simple solution could be to permit only block! datatype for /only: switch/only 2 [1 2 3 [print "found"]] another solution could be a different switch function, called switch-multiple or something like. The more complex: switch: func [ "Selects a choice and evaluates what follows it." [throw] value "Value to search for." cases [block!] "Block of cases to search." /only datatype "Evaluates only the first item of the datatype! which follows the choice" /default case "Default case if no others are found." ][ either value: either only [ if value: find cases value [ until [equal? datatype type? first value: next value] first value ] ][ select cases value ] [ do :value ][ either default [do case] [none] ] ] The more simple: switch: func [ "Selects a choice and evaluates what follows it." [throw] value "Value to search for." cases [block!] "Block of cases to search." /only "Evaluates only the first block! which follows the choice" /default case "Default case if no others are found." ][ either value: either only [ if value: find cases value [ until [block? first value: next value] first value ] ][ select cases value ] [ do :value ][ either default [do case] [none] ] ] --- Ciao Romano