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

Request For Comments

 [1/3] from: ryanc::iesco-dms::com at: 5-Apr-2001 17:45


What do you guys think of a good old fashioned case statement? case: func [ "If condition block is true, evaluates subsequent block." cases [block!] "Block alternating with conditions blocks and action blocks" /default default-case [block!] "Default case if no others found." ] [ forskip cases 2 [ if do first cases [ return do first next cases ] ] either default [ do default-case ][ none ] ] 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" ] ] 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" ] --Ryan Ryan Cole Programmer Analyst www.iesco-dms.com 707-468-5400 I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world. -Einstein

 [2/3] 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" ]

 [3/3] from: lmecir:mbox:vol:cz at: 7-Apr-2001 17:37


Since the thread is called "Request For Comments", I am picking up the glove. Here are some situations a successful implementation should handle: for i 1 10 1 [ print i case [ [i = 6] [break] [i = 7] [print "Error, shouldn't get here!"] ] ] paranoic: func [s [string!]] [ case [ [find s "x"] [return "x found"] [true] [return "x not found"] ] print "Error, shouldn't get here!" ] paranoic "" You can get an inspiration in: http://www.rebol.org/general/pif.r Regards Ladislav