On Sep 25, 2015 11:06 AM, "Charles R Harris" <charlesr.har...@gmail.com> wrote: > > > > On Fri, Sep 25, 2015 at 10:27 AM, Anne Archibald <archib...@astron.nl> wrote: >> >> goto! and comefrom! Together with exceptions, threads, lambda, super, generators, and coroutines, all we're lacking is call-with-current-continuation for the full list of impenetrable control-flow constructs. Oh, and lisp-style resumable exception handling. (Suggested syntax: drop(exception, value) to return control to where the exception was raised and make the raise statement return value.) >> >> On Thu, Sep 24, 2015 at 8:42 PM Charles R Harris < charlesr.har...@gmail.com> wrote: >>> >>> On Thu, Sep 24, 2015 at 12:13 PM, Yarko Tymciurak <yark...@gmail.com> wrote: >>>> >>>> >>>> >>>> I think there are more valid uses - I've read that "goto" basically is what a state machine does. >>>> Have a read of the brief implementation notes for "goto" in golang, for example. Goto may not be unreasonable to use, just most people would abuse. Sort of like "everyone shouldn't write assembly, but if you understand the machine, you can make good things happen". Without compiler/interpreter checks, more responsibility rests on the coder to keep out of trouble. >>> >>> >>> I would agree about state machines. When implemented using the standard control flow constructs they always look a bit artificial. >>> >> >> That depends what your "standard" control flow constructs are. Has anyone tried implementing a state machine using coroutines? They seem like a rather natural setup: each state is a coroutine that loops, doing the appropriate actions for the state and then handing control over to the coroutine for the next state. >> > > Might well do. TAOCP has an example elevator, passenger simulation that, IIRC, used coroutines. I think I may have even once used a language that had them (Algol 68?). It will be interesting to see what their inclusion in Python 3.5 leads to.
The coroutines in 3.5 are just syntactic sugar around features that were added in *2*.5 (yield expressions and yield from), so no need to wait :-). They fall far short of arbitrary continuations, though. I don't think it's particularly cumbersome to implement a state machine with one function per state and the return value specifying the new state -- there's a little more typing to set up the local variables and such each time, but if you have complex states then this seems like even an advantage over goto (since with goto you may have to set up local state by hand each time, basically reimplementing your own scoping mechanism). Of course if all your states are trivial then this overhead is just annoying. ...I suspect you actually might be able to implement resumable exceptions in cpython as a (very evil) third party module. I'm going to stop thinking about that now before I get too curious and do something I regret. Actually, don't stackless / greenlet give you full continuations? -n
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion