Re: Coroutines and argument tupling

2007-08-16 Thread Bjoern Schliessmann
Marshall T. Vandegrift wrote: > I'd seen the consumer decorator, and it certainly is cleaner than > just using a generator. I don't like how it hides the parameter > signature in the middle of the consumer function though, and it > also doesn't provide for argument default values. Mh, that may

Re: Coroutines and argument tupling

2007-08-16 Thread Marshall T. Vandegrift
Bjoern Schliessmann <[EMAIL PROTECTED]> writes: > The solution I'd use is a decorator that calls next automatically one > time after instantiation. Then you can use send normally, and don't > have to care about any initial parameters, which makes the code > clearer (initial parameters should be us

Re: Coroutines and argument tupling

2007-08-16 Thread Bjoern Schliessmann
Marshall T. Vandegrift wrote: > Without the decorator that becomes: > > gen = nextn(2) > print gen.next() # => [0, 1] > print gen.send(3) # => [2, 3, 4] > print gen.send(1) # => [5] > > The former is just that smidgen nicer, and allows you to continue > to make use of argument de

Re: Coroutines and argument tupling

2007-08-15 Thread Marshall T. Vandegrift
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > Do you really need a generator or co-routine to do this? Maybe > you can just use a closure: For my trivial example, sure -- there are lots of ways to do it. Here's a slightly better example: the `read' method of a file-like object which sequent

Re: Coroutines and argument tupling

2007-08-15 Thread [EMAIL PROTECTED]
On Aug 15, 3:37 pm, "Marshall T. Vandegrift" <[EMAIL PROTECTED]> wrote: > Bjoern Schliessmann <[EMAIL PROTECTED]> writes: > >> I'm trying to write a decorator which allows one to produce simple > >> coroutines by just writing a function as a generator expression > >> which re-receives it's argument

Re: Coroutines and argument tupling

2007-08-15 Thread Marshall T. Vandegrift
Bjoern Schliessmann <[EMAIL PROTECTED]> writes: >> I'm trying to write a decorator which allows one to produce simple >> coroutines by just writing a function as a generator expression >> which re-receives it's arguments as a tuple from each yield. > > May I ask why? Passing it the same argument

Re: Coroutines and argument tupling

2007-08-15 Thread Bjoern Schliessmann
Marshall T. Vandegrift wrote: > I'm trying to write a decorator which allows one to produce simple > coroutines by just writing a function as a generator expression > which re-receives it's arguments as a tuple from each yield. May I ask why? Passing it the same arguments over and over is no use

Coroutines and argument tupling

2007-08-15 Thread Marshall T. Vandegrift
Hi, I'm trying to write a decorator which allows one to produce simple coroutines by just writing a function as a generator expression which re-receives it's arguments as a tuple from each yield. For example: @coroutine def nextn(n=1): values = [] for i in itertools.count