Re: stackless language features
Lenard Lindstrom <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <Mahogany-0.66.0-4294655545-20040629-103856.00@pop3.norton.antivirus> |
On Mon, 28 Jun 2004 18:08:34 -0700 Mark Hahn <[email protected]> wrote: > I was going to start this thread in the new Prothon wiki ( > http://prothon.org/wiki ) as our first thread there, but when I created my > first page, it crashed so I don't think it's ready for prime-time. > > As our class discussion starts to wind down (hopefully), it is time to wind > up our discussion of stackless language features. I'll start the discussion > by giving some links to previous messages containing my proposal, > Christian's comments when he first joined our list, and Paul's thread about > continuations. Read these over and give your ideas for implementing > stackless features in Prothon. > > This is the last actual stackless proposal (before Christian joined us): > http://www.prothon.org/pipermail/prothon-user/2004-June/002124.html > > This is a thread-kill proposal. Later I found out that Ada works the same > way so I assume this will be approved by everyone without argument: > http://www.prothon.org/pipermail/prothon-user/2004-June/002125.html > > This is the thread when Christian first joined our list. It covers several > topics but it discusses stackless also. > http://www.prothon.org/pipermail/prothon-user/2004-June/002146.html > > This is a long thread where Paul argues for having real continuations in > Prothon. > http://www.prothon.org/pipermail/prothon-user/2004-June/002108.html > > This is my ultimate response to Paul. I basicly try to weasle out of the > issue by saying that we will eventually have continuations but not now: > http://www.prothon.org/pipermail/prothon-user/2004-June/002199.html > > As always if you don't make your own proposal I will and you know how bad > mine are :-) > This is very tentative: Declaring a thread or generator: thread <name> (arg, ...): <body> An enhanced yield statement can return a value. A generator example: thread fib(n): """Return first n Fibonacci numbers""" sum, prev = 1, 0 for i in n: yield sum sum, prev = sum + prev, sum iter = fib(5) for i in iter: print(i) In this case thread just replaces the gen keyword. A more general example: thread handlerA(obj): print(yield obj) print(rval) thread handlerB(obj): print(A(obj)) A = handlerA.thread() A.start(1) # Enters wait state on yield B = handlerB.thread() B.start(2) # May print # 1 # 2 # or # 2 # 1 Explicit calls on active thread objects take precidence over yield to avoid deadlocks. Lenard Lindstrom <[email protected]>