Hi Joel,

Your non-deterministic control structures are very very interesting. I'm
going to have to play with them a bit before I can tell whether I'll want
to use them regularly, but the ideas behind them are definitely worth
pondering.

It took me a little while to catch on to what EWD/DO is up to, though on
rereading your explanation I see that it was very clear. At first I thought
it just did each true conditions once in random order.

Just a thought, but EWD/DO might be useful as a control structure for
servers - waiting for input and responding to it each time in a
non-deterministic way, to keep the clients interested. I think it could be
used in this way as-is, by sandwiching a wait-for-input instruction into the
first condition with ALL, but perhaps it would be nicer to have a more
explicit way to do this.

Also, just for the sake of a little more non-determinism it would be nice
to have _REDUCE evaluate the conditions themselves in a random order, but I
don't think DO/NEXT would be quite up to the job.



I've played around a little more with Ladislav's PIF to get it more to my
liking. It doesn't go beyond C-style if ... else if ... else, but at least
it's more flexible than SWITCH and easier to read than nested EITHERs.
Doubt this will be of use to you - it succumbs to the "fall through the
default" temptation - but here goes:

pif: func [
        [throw]
    {polymorphic if with lazy evaluation and minimal checking}
    args [block!]
        /local choice
] [
        choice: false
    while [not tail? args] [
                if 1 = length? args [
                        choice: first args
                        break
                ]
        args: do/next args
                if all [
                        not unset? first args
                        first args
                ][
                        choice: first second args
                        break
                ]
                args: skip second args 1
        ]
        either block? choice [do choice][choice]
]


testcase: func [a b /local c] [
    pif [
        a < b [c: b - a print [b "-" a "=" c]]  ; block is DOne
        a > b {c: a - b print [a "-" b "=" c]}  ; other values just returned
                "they're equal"                         ; last single item is default
        ]
]

>> testcase 3 5
5 - 3 = 2
>> testcase 5 3
== {c: a - b print [a "-" b "=" c]}
>> testcase 5 5
== "they're equal"

See you,
Eric

Reply via email to