[REBOL] Rebol/Core User's Guide Re:
From: joel:neely:fedex at: 11-Oct-2000 10:34
Hi, Ladislav,
I haven't finished thinking through all of your comments, but one issue
jumped out at me so forcefully that I thought I'd go ahead and comment
on it...
[lmecir--geocities--com] wrote:
[...snip...]
> Scope of Variables
> page 8-30 REBOL/Core User Guide Version 2.3
> [Quote]
> For example, here is a signed if function that evaluates one of three blocks
> based on
> the sign of a conditional value:
> ifs: func [
> "If positive do block 1, zero do block 2, minus do 3"
> condition block1 block2 block3
> ][
> if positive? condition [return do block1]
> if negative? condition [return do block3]
> return do block2
> ]
> print ifs 12:00 - now/time ["morning"]["noon"]["night"]
> night
> [End Quote]
>
> The above definition doesn't work correctly, because it doesn't have the
> Throw attribute.
>
> [Corrected version]
> ifs: func [
> "If positive do block 1, zero do block 2, minus do 3"
> [throw]
> condition block1 block2 block3
> ][
> either positive? condition [do block1] [
> either negative? condition [do block3] [do block2]
> ]
> ]
> print ifs 12:00 - now/time ["morning"]["noon"]["night"]
> morning
> [End Corrected Version]
>
It's also incorrect because it assumes that successive uses of the argument
called condition will produce identical values! Consider this:
>> a: 1
== 1
>> b: to-paren [a: 0 - a]
== (a: 0 - a)
>> ifs b ["positive"] ["negative"] ["zero"]
== "zero"
(simply demonstrating, once again, the severe subtlety of REBOL!)
-jn-
--
; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677
REBOL [] print to-string debase decompress #{
789C0BCE0BAB4A7176CA48CAB53448740FABF474F3720BCC
B6F4F574CFC888342AC949CE74B50500E1710C0C24000000}