lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hey all,

I'm currently doing stuff that involves a mixture of random sampling and
enumeration.  I'm passing around a bunch of states that get modified,
and sometimes that requires choices of which path(s) to take.

The best thing I could come up with so far is to basically write in
continuation passing style, i.e.

    function foo( state )
        -- ...unconditional stuff...
        return choice { doThis, doThat, doSomethingElse } ( state )

which allows `choice` to either select a branch at random or run all of
the branches (with copies of the state).  (This "branch both ways"
wouldn't be possible with normal if/then/else or even coroutines –
there's no way to return to the previous point of execution.)

(I guess I'll also be experimenting with goto and "phase tags", if I
manage to make the choices stackless that might just be good enough…)

Has anyone else done something similar and/or knows a better / more
convenient / interesting / … alternative way to get multi-branching?

-- nobody