Script Library: 1218 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Discussion posts for script case.r

1
coccinelle
28-Nov-2005 13:03
REBOL

Case is native function

Contents:

Now case is a native function :

>> help case
USAGE:
     CASE block /all

DESCRIPTION:
     Evaluates each condition, and when true, evaluates what follows it.
     CASE is a native value.

ARGUMENTS:
     block -- Block of cases (conditions followed by values) (Type: block)

REFINEMENTS:
     /all -- Evaluate all cases (do not stop at first true case)

Another case function exists also in the cookbook with the following source :

case: func [  
    "Find a condition and evaluates what follows it."  
    [throw]  
    cases [block!] "Block of cases to evaluate."  
    /default  
        case "Default case if no others are found."  
    /local condition body  
][  
    while [not empty? cases][  
        set [condition cases] do/next cases  
        if condition [  
            body: first cases  
            break  
        ]  
        cases: next cases  
    ]  
    do any [
        body
        case
    ]  
]
MakeDoc2 by REBOL- 28-Nov-2005
2
cmdicely
30-Nov-2005 0:22
Well, that was a waste of time then (not really, it was a good exercise, 
if nothing else). 


Really, though, I needed -- well, wanted --  "case" for something 
I was working on, and thought I had seen it somewhere, but it wasn't 
in the docs I checked on the web, and I didn't even think to check 
the console help or the cookbook.


The worst part is I've realized the version I uploaded originally 
is slightly broken...


Blah. Well, next time I'll have to be more careful not to reinvent 
the wheel.