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


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

Reply via email to