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

[REBOL] Ifs Re:

From: joel:neely:fedex at: 11-Oct-2000 16:20

Hi, all... In honor of the newest REBOL book (and for those of us who can't count to three in proper order, such as myself! ;-) and inspired by the keywords feature of Common Lisp, I offer yet another ifs , which doesn't care in which order the actions are specified:
>> a: 1
== 1
>> ifs-for-dummies a [positive: ["plus"] zero: ["zip"] negative: ["minus"]]
== "plus"
>> ifs-for-dummies a [zero: ["zip"] positive: ["plus"] negative: ["minus"]]
== "plus"
>> ifs-for-dummies a [negative: ["minus"] zero: ["zip"] positive: ["plus"]]
== "plus" whether they are all specified:
>> ifs-for-dummies a [positive: ["biggerthanzero"]]
== "biggerthanzero"
>> ifs-for-dummies a [negative: ["smallerthanzero"]] >> ifs-for-dummies a [zero: ["equaltozero"]] >> ifs-for-dummies a [zero: ["equaltozero"] positive: ["bigger, again!"]]
== "bigger, again!" or whether the selector has unstable side-effects:
>> a: 1
== 1
>> b: to-paren [a: 0 - a]
== (a: 0 - a)
>> ifs-for-dummies b [negative: ["minus"] zero: ["zip"] positive: ["plus"]]
== "minus"
>> ifs-for-dummies b [negative: ["minus"] zero: ["zip"] positive: ["plus"]]
== "plus"
>> ifs-for-dummies b [negative: ["minus"] zero: ["zip"] positive: ["plus"]]
== "minus"
>> ifs-for-dummies b [negative: ["minus"] zero: ["zip"] positive: ["plus"]]
== "plus" This new candidate (which will run if evaluated, but not if elected), has a running mate: fortranif: make object! [ positive: [] negative: [] zero: [] selector: 0 compute: func [[throw] selexpr] [ selector: selexpr either positive? selector [ do positive ][ either negative? selector [ do negative ][ do zero ] ] ] ] and a campaign promise: ifs-for-dummies: func [[throw] selexp conseq [block!] /local actor] [ actor: make fortranif conseq actor/compute selexp ] (In case you're wondering, the news coverage of the US election campaigns hasn't affected me at all! "My fellow REBOLians...") -jn- Coding at the speed of a dummy! -- ; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677 REBOL [] print to-string debase decompress #{ 789C0BCE0BAB4A7176CA48CAB53448740FABF474F3720BCC B6F4F574CFC888342AC949CE74B50500E1710C0C24000000}