Re: [Python-Dev] 'stackless' python?

Guido van Rossum writes:
This helped me a lot, and is the angle used in "Essentials of Programming Languages": Usually when folks refer to a 'stack', they're refering to an *implementation* of the stack data type: really an optimization that assumes an upper bound on stack size, and that things will only be pushed and popped in order. If you were to implement a language's variable and execution stacks with actual data structures (linked lists), then it's easy to see what's needed: the head of the list represents the current state. As functions exit, they pop things off the list. The reason I brought this up (during a lull!) was that Python is already paying all of the cost of heap-allocated frames, and it didn't seem to me too much of a leap from there.
1. All program state is somehow contained in a single execution stack. Yup.
Yes, Scheme is pro-functional... but it has arrays, i/o, and set-cdr!, all the things that make it 'impure'. I think shallow copies are what's expected. In the examples I have, the continuation is kept in a 'register', and call/cc merely packages it up with a little function wrapper. You are allowed to stomp all over lexical variables with "set!".
http://www.nightmare.com/stuff/samefringe.scm Somewhere I have an example of coroutines being used for parsing, very elegant. Something like one coroutine does lexing, and passes tokens one-by-one to the next level, which passes parsed expressions to a compiler, or whatever. Kinda like pipes.
Yes... I think backtracking would be an example of this. You're doing a search on a large space (say a chess game). After a certain point you want to try a previous fork, to see if it's promising, but you don't want to throw away your current work. Save it, then unwind back to the previous fork, try that option out... if it turns out to be better then toss the original.
I think you're probably right here - usually there are heavy restrictions on what kind of data can pass through the C interface. But I know of at least one Scheme (mzscheme/PLT) that uses conservative gc and has c/c++ interfaces. [... dig dig ...]

"SR" == rushing <rushing@nightmare.com> writes:
SR> Somewhere I have an example of coroutines being used for SR> parsing, very elegant. Something like one coroutine does SR> lexing, and passes tokens one-by-one to the next level, which SR> passes parsed expressions to a compiler, or whatever. Kinda SR> like pipes. This is the first example that's used in Structured Programming (Dahl, Djikstra, and Hoare). I'd be happy to loan a copy to any of the Python-dev people who sit nearby. Jeremy

"SR" == rushing <rushing@nightmare.com> writes:
SR> Somewhere I have an example of coroutines being used for SR> parsing, very elegant. Something like one coroutine does SR> lexing, and passes tokens one-by-one to the next level, which SR> passes parsed expressions to a compiler, or whatever. Kinda SR> like pipes. This is the first example that's used in Structured Programming (Dahl, Djikstra, and Hoare). I'd be happy to loan a copy to any of the Python-dev people who sit nearby. Jeremy
participants (2)
-
Jeremy Hylton
-
rushing@nightmare.com