Hi Joel,

I knew about that issue, but considered the Throw attribute as absolutely
necessary in this case (the chapter follows the one describing Throw/Catch
attributes AFAIR). You are right. To be correct, it should have been like
this:

ifs: func [
    {If positive do block 1, zero do block 2, minus do 3}
    [throw]
    condition [number!]
    block1 [block!]
    block2 [block!]
    block3 [block!]
] [
    either positive? condition [do block1] [
        either negative? condition [do block3] [do block2]
    ]
]

Regards
    Ladislav

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 11, 2000 5:34 PM
Subject: [REBOL] Rebol/Core User's Guide Re:


> 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...
>
> [EMAIL PROTECTED] 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  [EMAIL PROTECTED]  901-263-4460  38017/HKA/9677
> REBOL []  print to-string debase decompress #{
>     789C0BCE0BAB4A7176CA48CAB53448740FABF474F3720BCC
>     B6F4F574CFC888342AC949CE74B50500E1710C0C24000000}
>
>

Reply via email to