Re: Suggesting a new feature - "Inverse Generators"

2005-03-26 Thread Oren Tirosh
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Hmmm, I like the terminology consumers better than acceptors. Here's an implementation of Python consumers using generators: http://groups.google.co.uk/[EMAIL PROTECTED] Oren -- http://mail.python.org/mailman

Re: Suggesting a new feature - "Inverse Generators" -- tangential topic

2005-03-26 Thread phil_nospam_schmidt
> The ability to have 'full coroutines', or at least more 'coroutiney > behaviour' than is provided by generators alone, was I think what I was Jordan, This is somewhat off-topic, but perhaps you might be interested in taking a look at the Lua language (http://www.lua.org/). It supports coroutine

Re: Suggesting a new feature - "Inverse Generators"

2005-03-26 Thread Jordan Rastrick
Hmmm, I like the terminology consumers better than acceptors. The ability to have 'full coroutines', or at least more 'coroutiney behaviour' than is provided by generators alone, was I think what I was trying to get at with my original idea, although things got a bit sidetracked by the way I focus

Re: Suggesting a new feature - "Inverse Generators"

2005-03-26 Thread Andrew Koenig
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > But I'm not so much interested in alternate solutions to the problem > itself, which is to be honest trivial. I'm intereseted in the > implications of the imaginary solution of the Acceptor function. Of course. But

Re: Suggesting a new feature - "Inverse Generators"

2005-03-26 Thread Peter Otten
Jordan Rastrick wrote: >> No, it's nothing special about groupby. record simply stores its > state in a >> mutable default parameter. This isn't general good practice: at > least you have >> to be careful with it. You can see the behavior in the following > example: >> >>> def accumulate(valu

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Jordan Rastrick
> No, it's nothing special about groupby. record simply stores its state in a > mutable default parameter. This isn't general good practice: at least you have > to be careful with it. You can see the behavior in the following example: > >>> def accumulate(value, accum = []): > ... accum.

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Bengt Richter
On Fri, 25 Mar 2005 12:07:23 -0800, Michael Spencer <[EMAIL PROTECTED]> wrote: >Scott David Daniels wrote: >> Michael Spencer wrote: >> >>> itertools.groupby enables you to do this, you just need to define a >>> suitable grouping function, that stores its state: >> >> >> Michael, this would ma

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Scott David Daniels
Michael Spencer wrote: Scott David Daniels wrote: Michael Spencer wrote: OK, will do. What would you call it? Something like: "Stateful grouping of iterable items" How about "Using groupby to fill lines"? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-l

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Michael Spencer
Scott David Daniels wrote: Michael Spencer wrote: itertools.groupby enables you to do this, you just need to define a suitable grouping function, that stores its state: Michael, this would make a great Python Cookbook Recipe. OK, will do. What would you call it? Something like: "Stateful groupi

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Scott David Daniels
Michael Spencer wrote: itertools.groupby enables you to do this, you just need to define a suitable grouping function, that stores its state: Michael, this would make a great Python Cookbook Recipe. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Bengt Richter
On Fri, 25 Mar 2005 08:46:12 -0800, Michael Spencer <[EMAIL PROTECTED]> wrote: >Tim Hochberg wrote: >> Jordan Rastrick wrote: >> > >itertools.groupby enables you to do this, you just need to define a suitable >grouping function, that stores its state: > >For example, if short lines should be app

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Terry Reedy
Terminology: To me and some (most?) others posting here and, I believe, both the docs and the common meaning of 'generator', a Python generator is the particular kind of iterator that produces multiple values on request and which is created by the generator function that you write. Acceptors (c

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Serge Orlov
Michael Spencer wrote: > > Still, this is fascinating going to have to spend some time > > experimenting with groupby as soon as I get a chance > > > Experimenting is good. So is the the documentation: > http://docs.python.org/tut/tut.html Reading documentation is a good idea, but I think

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Michael Spencer
Jordan Rastrick wrote: Wow, if I'm going to get replies (with implemented solutions!) this quickly, I'll post here more often :-) That is indeed typical of this most attentive group :-) Its taken me a while to get a rough understanding of this code, but I think I have some idea. It is just an exam

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Jordan Rastrick
Wow, if I'm going to get replies (with implemented solutions!) this quickly, I'll post here more often :-) This is the most different to my solution, and also the shortest, and therefore the most interesting, reply so far. Its also the last one I'll reply to before I go to bed. Its taken

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Diez B. Roggisch
> > I'll try to reduce my pages of ranting to a single question. In > posting, i was wondering if the "syntactic sugar" (Acceptors) that i > invented to implement the solution is of any general interest. So are > there maybe examples less straightforward than this one, where > Acceptors work bette

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Jordan Rastrick
Yes, granted. This is basically the same as Andrew's reply, except with Iterators in place of generators, so I'll let my answer to that stand. In fact, its my solution, but with iter.next() in place of accept :) This is probably something like how I wanted to solve the problem when I first was lo

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Michael Spencer
Tim Hochberg wrote: Jordan Rastrick wrote: itertools.groupby enables you to do this, you just need to define a suitable grouping function, that stores its state: For example, if short lines should be appended to the previous line: from itertools import groupby linesource = """\ Here is a long lin

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Jordan Rastrick
Thanks for the very fast feedback :) I specifically set optionalline = None to deal with that bug you mentioned, with the implicit assumption createRecord knows how to deal with a None argument. If that guard got destroyed in the copy paste process, my bad. As for you solution, yes, you could do

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Tim Hochberg
Jordan Rastrick wrote: [CHOP] Behold: # An Acceptor/Generator!!! def combineIntoRecords(): optionalline = None # We may not get given a value for this line accept firstline accept secondline if condition(secondline): accept optionalline accept lastline

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Andrew Koenig
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > def combineIntoRecord(): # This is an acceptor function > optionalline = None # We may not get given a value for this line > accept firstline > accept secondline > if condition(secondline): >

Re: Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Jordan Rastrick
Sorry about the mangled formatting... like i said, first time on Usenet Suggestions, comments, replies, etc most welcome. This definitely includes replies of the form: "This is stupid, because..." provided it isnt followed with "youre a jerk who knows nothing. Period." Heres a follow up rant in

Suggesting a new feature - "Inverse Generators"

2005-03-25 Thread Jordan Rastrick
First, a disclaimer. I am a second year Maths and Computer Science undergraduate, and this is my first time ever on Usenet (I guess I'm part of the http generation). On top of that, I have been using Python for a grand total of about a fortnight now. Hence, I apologise if what follows is a stupid s