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