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

[REBOL] Re: Switch with refinements/hmmm!

From: media:quazart at: 1-Nov-2001 7:56

> If you expect at most one refinement to be used > > refine-switch: func [ /refa /refb /refc ] [ > either refa [ > print "ref A" > ][either refb [ > print "ref B" > ][either refc [ > print "ref C" > ][ > print "NO ref" > ]]] > ]
I just thought I'd share some knowledge... The above can also be coded like so: refine-switch: func [ /refa /refb /refc ] [ any[ all [refa print "ref A"] all [refb print "ref b"] all [refc print "ref c"] print "NO ref" ] ] this sort of fixes doc kimbel's approach IMHO here, the first reference to be set will be returned... you could also code the following: refine-switch: func [ /refa /refb /refc ] [ any[ all [refa refb refc print "all refs are set !"] all [refa refb print "ref a & b"] all [refa refc print "ref a & c"] all [refb refc print "ref b & c"] all [refa print "ref a"] all [refb print "ref b"] all [refc print "ref c"] print "NO ref" ] ] this approach actually handles all cases... either all, two or only one of the refs may be set, and you can react differently to each different case. the nice thing about the any and all combo is that its VERY easy to create large or complex value filters. the syntax so simple, it doesn't make such a bad program if you insert the values by hand like I did above... doing that in IF/ELSE would have been a MAJOR pain... just try it you'll see. its also very to debug like I did above. my two cents.