Well, the problem is, that you are trying to disobey the KISS rule. That
rule means, that your signed-if-for-dummies should do one thing and do it
well. I think, that it should execute the properly chosen block. It shoudn't
try to evaluate its first argument at any price, because supplying it is a
work for the caller IMO. I am pretty sure, that the code is much more
"brittle" and cryptic, than the proper solution, which should work for
useful first argument values and not for any garbage. E.g. your solution has
the worst possible property of any algorithm: there are some inputs, for
which the algorithm doesn't stop.

Regards
    Ladislav

> Hi, Ladislav,
>
> That was severely subtle!  (And AFAIAC sounded the death knell on the
notion
> that REBOL is a simple language for non-programmers! ;-)
>
> [EMAIL PROTECTED] wrote:
> >
> > Hi,
> >
> > a stupid example:
> >
>
>     replace read previous-message-in-thread "stupid" "challenging"
>
> >
> > f: func [x [any-type!]] [1]
> > b: to paren! [to paren! [:f]]
> > ifs-for-dummies-who-play-with-fire b [positive: [print "positive"]
negative:
> > [print "negative"] zero: [print "zero"]]
> >
> > The result:
> >
> > zero
> > == 1
> >
>
> Even knowing the dynamic, code=data=code=data... nature of REBOL, I hadn't
> thought of the possibility of supplying a value that totally changes the
> evaluation pattern of another bit of code.  Of course, this creates a
whole
> new level of threat models for trying to write defenses against
potentially
> hostile external code.
>
> At any rate, the following mod seems to close the wormhole:
>
>     signed-choice: make object! [
>         positive: []
>         negative: []
>         zero:     []
>         selector: 0
>         compute:  func [[throw] selexpr] [
>             selector: (unravel selexpr)
>             either positive? selector [
>                 do positive
>             ][
>                 either negative? selector [
>                     do negative
>                 ][
>                     do zero
>     ]   ]   ]   ]
>
> ...allowing...
>
>     ifs-for-dummies-who-play-with-fire b [
>        positive: ["+"] negative: ["-"] zero: ["0"]
>     ]
>
>     == "+"
>
>     ifs-for-dummies-who-play-with-fire b [
>        positive: ["+"] negative: ["-"] zero: ["0"]
>     ]
>
>     == "+"
>
> Thanks!
>
> -jn-
>
>

Reply via email to