[REBOL] Re: Request For Comments
From: ryanc:iesco-dms at: 6-Apr-2001 9:37
This morning I looked at that code and thought to myself "Those condition
blocks should work like 'all." So here is the resulting update.
--Ryan
REBOL [
Title: "Case Statement and Test"
]
case: func [
"If all of condition block is true, subsequent block is evaluated."
cases [block!] "Block alternating with condition blocks and action
blocks"
/default
default-case [block!] "Defualt case if no others found."
] [
forskip cases 2 [
if all first cases [
return do first next cases
]
]
either default [ do default-case ][ none ]
]
; Test 'all functionality of condition blocks
a: 8
b: 8
c: 8
confirm case [
[ c = 32 b = 8 a = 4 ] [ probe "C = 32 & B = 8 & A = 4" ]
[ a = b b = 8 c <> b ] [ probe "A = B & B = 8" ]
[ a = b c = b ] [ probe "A = B & C = B" ]
[ a = ( b + c ) ] [ probe "A = B + C" ]
[ c = ( a + b ) ] [ probe "C = A + B" ]
]
; Test found case
a: 1
b: 2
c: 3
confirm case [
[ c = a ] [ probe "C = A" ]
[ a = b ] [ probe "A = B" ]
[ a = ( b + c ) ] [ probe "A = B + C" ]
[ c = ( a + b ) ] [ probe "C = A + B" ]
]
; Test not found case
a: 22
b: 33
c: 44
confirm form case [
[ c = a ] [ probe "C = A" ]
[ a = b ] [ probe "A = B" ]
[ a = ( b + c ) ] [ probe "A = B + C" ]
[ c = ( a + b ) ] [ probe "C = A + B" ]
]
; Test defualt case
a: 11
b: 200
c: 32
confirm case/default [
[ c = a ] [ probe "C = A" ]
[ a = b ] [ probe "A = B" ]
[ a = ( b + c ) ] [ probe "A = B + C" ]
[ c = ( a + b ) ] [ probe "C = A + B" ]
] [ probe "default" ]