Re: generator/coroutine terminology

2015-04-18 Thread CHIN Dihedral
On Friday, March 13, 2015 at 5:36:35 PM UTC+8, Marko Rauhamaa wrote: > Rustom Mody : > > > Nice demo of the same confusing terminology we are talking about. > > Why don't you just stick with the terminology of the language > specification? I think your students are going to be more confused if >

Re: generator/coroutine terminology

2015-04-18 Thread Albert van der Horst
In article <551e2cfd$0$11123$c3e8...@news.astraweb.com>, Steven D'Aprano wrote: >On Wednesday 01 April 2015 00:18, Albert van der Horst wrote: > >> In article <55062bda$0$12998$c3e8da3$54964...@news.astraweb.com>, >> Steven D'Aprano wrote: > >>>The biggest difference is syntactic. Here's an ite

Re: generator/coroutine terminology

2015-04-02 Thread Paul Rubin
alb...@spenarnc.xs4all.nl (Albert van der Horst) writes: > You should give an example of usage. As a newby I'm not up to > figuring out the specification from source for > something built of the mysterious __ internal > thingies. In reality because of generator expressions, the yield statement, an

Re: generator/coroutine terminology

2015-04-02 Thread Steven D'Aprano
On Wednesday 01 April 2015 00:18, Albert van der Horst wrote: > In article <55062bda$0$12998$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: >>The biggest difference is syntactic. Here's an iterator which returns a >>never-ending sequence of squared numbers 1, 4, 9, 16, ... >> >>c

Re: generator/coroutine terminology

2015-03-31 Thread Chris Angelico
On Wed, Apr 1, 2015 at 2:03 AM, Albert van der Horst wrote: > class Squares: > def __init__(self): > self.i = 0 > def __next__(self): > self.i += 1 > return self.i**2 > def __iter__(self): > return self > > albert@cherry:/tmp$ python > Python 2.6.6 (r266

Re: generator/coroutine terminology

2015-03-31 Thread Albert van der Horst
In article , Dave Angel wrote: >On 03/31/2015 09:18 AM, Albert van der Horst wrote: >> In article <55062bda$0$12998$c3e8da3$54964...@news.astraweb.com>, >> Steven D'Aprano wrote: > >>> >>> The biggest difference is syntactic. Here's an iterator which returns a >>> never-ending sequence of squar

Re: generator/coroutine terminology

2015-03-31 Thread Dave Angel
On 03/31/2015 09:18 AM, Albert van der Horst wrote: In article <55062bda$0$12998$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: The biggest difference is syntactic. Here's an iterator which returns a never-ending sequence of squared numbers 1, 4, 9, 16, ... class Squares:

Re: generator/coroutine terminology

2015-03-31 Thread Albert van der Horst
In article <55062bda$0$12998$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: >Marko Rauhamaa wrote: > >> Chris Angelico : >> >>> On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: Is it necessary/useful for a Python application programmer to be conscious of the differen

Re: generator/coroutine terminology

2015-03-31 Thread Albert van der Horst
In article <83d579c1-ab61-4a3d-a834-e65d28eac...@googlegroups.com>, Rustom Mody wrote: >On Saturday, March 14, 2015 at 8:59:22 PM UTC+5:30, Rustom Mody wrote: >> On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano wrote: >> > >> > A generator (function) may be a function which re

Re: generator/coroutine terminology

2015-03-16 Thread Mark Lawrence
On 17/03/2015 03:33, Rustom Mody wrote: On Tuesday, March 17, 2015 at 8:55:27 AM UTC+5:30, Mark Lawrence wrote: On 17/03/2015 03:18, Rustom Mody wrote: On Tuesday, March 17, 2015 at 8:37:25 AM UTC+5:30, Mark Lawrence wrote: Ok Let me throw out a suggestion: - potato is a generator - t

Re: generator/coroutine terminology

2015-03-16 Thread Rustom Mody
On Tuesday, March 17, 2015 at 8:55:27 AM UTC+5:30, Mark Lawrence wrote: > On 17/03/2015 03:18, Rustom Mody wrote: > > On Tuesday, March 17, 2015 at 8:37:25 AM UTC+5:30, Mark Lawrence wrote: > >>> > >>> Ok Let me throw out a suggestion: > >>>- potato is a generator > >>>- tomato is a cursor.

Re: generator/coroutine terminology

2015-03-16 Thread Mark Lawrence
On 17/03/2015 03:18, Rustom Mody wrote: On Tuesday, March 17, 2015 at 8:37:25 AM UTC+5:30, Mark Lawrence wrote: Ok Let me throw out a suggestion: - potato is a generator - tomato is a cursor. Acceptable? No. In Python potato is a generator function, tomato is a generator. Why complica

Re: generator/coroutine terminology

2015-03-16 Thread Mario Figueiredo
On Mon, 16 Mar 2015 19:52:59 -0700 (PDT), Rustom Mody wrote: > >When we go from 'simple-generators' to coroutine-generators there seem to be >bigger conceptual problems and implementation-gaffes. >Quite frankly I hardly understand this part. There's a line after which terminology just becomes pe

Re: generator/coroutine terminology

2015-03-16 Thread Rustom Mody
On Tuesday, March 17, 2015 at 8:37:25 AM UTC+5:30, Mark Lawrence wrote: > > > > Ok Let me throw out a suggestion: > > - potato is a generator > > - tomato is a cursor. > > Acceptable? > > > > No. In Python potato is a generator function, tomato is a generator. > Why complicate something that

Re: generator/coroutine terminology

2015-03-16 Thread Mark Lawrence
On 17/03/2015 02:52, Rustom Mody wrote: On Monday, March 16, 2015 at 11:50:33 PM UTC+5:30, Mark Lawrence wrote: On 16/03/2015 14:37, Rustom Mody wrote: On Monday, March 16, 2015 at 7:57:08 PM UTC+5:30, Mark Lawrence wrote: On 16/03/2015 14:19, Rustom Mody wrote: == Anyways

Re: generator/coroutine terminology

2015-03-16 Thread Rustom Mody
On Monday, March 16, 2015 at 11:50:33 PM UTC+5:30, Mark Lawrence wrote: > On 16/03/2015 14:37, Rustom Mody wrote: > > On Monday, March 16, 2015 at 7:57:08 PM UTC+5:30, Mark Lawrence wrote: > >> On 16/03/2015 14:19, Rustom Mody wrote: > >>> == > >>> Anyways... > >>> > >>> Yes 15

Re: generator/coroutine terminology

2015-03-16 Thread Mark Lawrence
On 16/03/2015 14:37, Rustom Mody wrote: On Monday, March 16, 2015 at 7:57:08 PM UTC+5:30, Mark Lawrence wrote: On 16/03/2015 14:19, Rustom Mody wrote: == Anyways... Yes 15 years are past. I dont expect the def can be revoked now. [As far as I am concerned its a minor wart]

Re: generator/coroutine terminology

2015-03-16 Thread Marko Rauhamaa
Ian Kelly : > Or inversely I write a normal utility function that is called from > coroutines, then later add a "yield from" to it, and now I have to go > back and revise every place where it's called to make those use "yield > from" as well. That is actually quite awkward. Smooth interlocking of

Re: generator/coroutine terminology

2015-03-16 Thread Ian Kelly
On Mon, Mar 16, 2015 at 9:09 AM, Marko Rauhamaa wrote: > Ian Kelly : > >> For generators, the descriptive keyword ("yield") could be buried >> *anywhere* in that block. One can glance at a generator function and >> fail to notice that it is a generator function. This is the one that >> really bugs

Re: generator/coroutine terminology

2015-03-16 Thread Marko Rauhamaa
Ian Kelly : > For generators, the descriptive keyword ("yield") could be buried > *anywhere* in that block. One can glance at a generator function and > fail to notice that it is a generator function. This is the one that > really bugs me about reuse of "def", although you are correct that > this

Re: generator/coroutine terminology

2015-03-16 Thread Rustom Mody
On Monday, March 16, 2015 at 8:07:22 PM UTC+5:30, Rustom Mody wrote: > I would gladly do that if it was a minor correction here and there. > But the problem is a bit deeper even though it can be kept mostly¹ in the docs > and not modify any syntax/semantics of python. > > In particular for: > > d

Re: generator/coroutine terminology

2015-03-16 Thread Ian Kelly
On Mon, Mar 16, 2015 at 7:39 AM, Steven D'Aprano wrote: > On Mon, 16 Mar 2015 11:51 pm, Rustom Mody wrote: > >> It may help to read this 15 year old thread starting >> https://mail.python.org/pipermail/python-dev/2001-June/015478.html >> to see how many python stalwarts dont like the current state

Re: generator/coroutine terminology

2015-03-16 Thread Ian Kelly
On Mon, Mar 16, 2015 at 8:32 AM, Steven D'Aprano wrote: > On Tue, 17 Mar 2015 12:13 am, Marko Rauhamaa wrote: > >> If I get an iterator from a black box source, I don't know if I'm >> allowed/supposed to call close() on it. > > In no particular order: > > #1 > if hasattr(some_iterator, 'close'): >

Re: generator/coroutine terminology

2015-03-16 Thread Rustom Mody
On Monday, March 16, 2015 at 7:57:08 PM UTC+5:30, Mark Lawrence wrote: > On 16/03/2015 14:19, Rustom Mody wrote: > > == > > Anyways... > > > > Yes 15 years are past. > > I dont expect the def can be revoked now. > > [As far as I am concerned its a minor wart] > > But the mess ar

Re: generator/coroutine terminology

2015-03-16 Thread Steven D'Aprano
On Tue, 17 Mar 2015 01:35 am, Steven D'Aprano wrote: > On Tue, 17 Mar 2015 01:19 am, Rustom Mody wrote: > >> On Monday, March 16, 2015 at 7:10:03 PM UTC+5:30, Steven D'Aprano wrote: >>> And of course, from a comp science theoretic perspective, >>> generators are a kind of subroutine, not a kind o

Re: generator/coroutine terminology

2015-03-16 Thread Steven D'Aprano
On Tue, 17 Mar 2015 01:19 am, Rustom Mody wrote: > On Monday, March 16, 2015 at 7:10:03 PM UTC+5:30, Steven D'Aprano wrote: >> And of course, from a comp science theoretic perspective, >> generators are a kind of subroutine, not a kind of type. > > You just showed Marko a few posts back, that > A

Re: generator/coroutine terminology

2015-03-16 Thread Mark Lawrence
On 16/03/2015 14:19, Rustom Mody wrote: On Monday, March 16, 2015 at 7:10:03 PM UTC+5:30, Steven D'Aprano wrote: And of course, from a comp science theoretic perspective, generators are a kind of subroutine, not a kind of type. You just showed Marko a few posts back, that A generator is a spec

Re: generator/coroutine terminology

2015-03-16 Thread Steven D'Aprano
On Tue, 17 Mar 2015 12:13 am, Marko Rauhamaa wrote: > If I get an iterator from a black box source, I don't know if I'm > allowed/supposed to call close() on it. In no particular order: #1 if hasattr(some_iterator, 'close'): some_iterator.close() #2 close = getattr(some_iterator, 'close',

Re: generator/coroutine terminology

2015-03-16 Thread Rustom Mody
On Monday, March 16, 2015 at 7:10:03 PM UTC+5:30, Steven D'Aprano wrote: > And of course, from a comp science theoretic perspective, > generators are a kind of subroutine, not a kind of type. You just showed Marko a few posts back, that A generator is a special case of an iterator. And you wrote t

Re: generator/coroutine terminology

2015-03-16 Thread Steven D'Aprano
On Mon, 16 Mar 2015 11:51 pm, Rustom Mody wrote: > It may help to read this 15 year old thread starting > https://mail.python.org/pipermail/python-dev/2001-June/015478.html > to see how many python stalwarts dont like the current state of affairs /s/dont/didn't/ That's a fifteen year old thread,

Re: generator/coroutine terminology

2015-03-16 Thread Chris Angelico
On Mon, Mar 16, 2015 at 10:51 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > Just for the record, it's not just name bindings that make a generator > behave as a coroutine. E.g.: > > py> def co(): > ... print( (yield 1) + 2 ) > ... > py> a = co() > py> next(a) > 1 > py> a.send(98) > 100

Re: generator/coroutine terminology

2015-03-16 Thread Marko Rauhamaa
Rustom Mody : > On Monday, March 16, 2015 at 6:02:48 PM UTC+5:30, Marko Rauhamaa wrote: >> So what we have now is: >> (1) plain iterators >> (2) generator iterators >> (3) coroutine generator iterators > >> (1) and (2) are not unified, which I don't like. > > Can you expand on that a bit? (

Re: generator/coroutine terminology

2015-03-16 Thread Rustom Mody
On Monday, March 16, 2015 at 6:02:48 PM UTC+5:30, Marko Rauhamaa wrote: > So what we have now is: > > (1) plain iterators > > (2) generator iterators > > (3) coroutine generator iterators > > (1) and (2) are not unified, which I don't like. Can you expand on that a bit? It may help to

Re: generator/coroutine terminology

2015-03-16 Thread Jonas Wielicki
On 16.03.2015 13:02, Steven D'Aprano wrote: > (To be honest, I'm not even sure what the use-case for close() on coroutines > is in the first place. If you don't want to send any more items into it, > just don't send any more items into it.) Just like with file-likes, it is useful to clean up resou

Re: generator/coroutine terminology

2015-03-16 Thread Marko Rauhamaa
Steven D'Aprano : > (To be honest, I'm not even sure what the use-case for close() on > coroutines is in the first place. If you don't want to send any more > items into it, just don't send any more items into it.) Without close(), you might leave resources hanging. See PEP 325: Rejected in

Re: generator/coroutine terminology

2015-03-16 Thread Marko Rauhamaa
Steven D'Aprano : > If I .send() into either of the generators above, its a conceptual > mistake and I should get an error. The fact that I don't is an > implementation detail, and one which hopefully will be fixed. So what we have now is: (1) plain iterators (2) generator iterators (3)

Re: generator/coroutine terminology

2015-03-16 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Anyway, calling close() on an iterator can be a necessary requirement > even in ordinary generator usage. Only now they have to know if the > underlying iterator was sired by a generator or some other constructor. Can you give an actual example of that? (To be honest, I'm

Re: generator/coroutine terminology

2015-03-16 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Chris Angelico : > >> On Mon, Mar 16, 2015 at 6:12 PM, Marko Rauhamaa wrote: >>> >>> I was actually referring to the offered API. It still seems to me like >>> all iterators could offer close(), send() and throw(). Why? To make all >>> iterators drop-in replacements of ea

Re: generator/coroutine terminology

2015-03-16 Thread Steven D'Aprano
Chris Angelico wrote: > On Mon, Mar 16, 2015 at 7:36 PM, Steven D'Aprano > wrote: >> I expect that the interpreter can tell the difference between >> >> yield spam >> >> and >> >> x = yield spam >> >> and only allow send(), close() and throw() on generators which include >> the second for

Re: generator/coroutine terminology

2015-03-16 Thread Chris Angelico
On Mon, Mar 16, 2015 at 7:36 PM, Steven D'Aprano wrote: > I expect that the interpreter can tell the difference between > > yield spam > > and > > x = yield spam > > and only allow send(), close() and throw() on generators which include the > second form. If it can't, then that's a limitat

Re: generator/coroutine terminology

2015-03-16 Thread Steven D'Aprano
On Monday 16 March 2015 18:12, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >>> What features do generator iterators provide on top of generic >>> iterators? >> >> The biggest difference is syntactic. Here's an iterator which returns a >> never-ending sequence of squared n

Re: generator/coroutine terminology

2015-03-16 Thread Marko Rauhamaa
Ian Kelly : > If on the other hand these methods were to be added to the iterator > protocol, it would just create unnecessary implementation overhead for > the 99.99% of non-generator iterators that are under no illusions > about the fact that they aren't coroutines. Why should (x for x in [

Re: generator/coroutine terminology

2015-03-16 Thread Marko Rauhamaa
Chris Angelico : > On Mon, Mar 16, 2015 at 6:12 PM, Marko Rauhamaa wrote: >> >> I was actually referring to the offered API. It still seems to me like >> all iterators could offer close(), send() and throw(). Why? To make all >> iterators drop-in replacements of each other. > > [...] > > That jus

Re: generator/coroutine terminology

2015-03-16 Thread Ian Kelly
On Mon, Mar 16, 2015 at 1:12 AM, Marko Rauhamaa wrote: > I was actually referring to the offered API. It still seems to me like > all iterators could offer close(), send() and throw(). Why? To make all > iterators drop-in replacements of each other. The purpose of close, send and throw is to impl

Re: generator/coroutine terminology

2015-03-16 Thread Chris Angelico
On Mon, Mar 16, 2015 at 6:12 PM, Marko Rauhamaa wrote: > > I was actually referring to the offered API. It still seems to me like > all iterators could offer close(), send() and throw(). Why? To make all > iterators drop-in replacements of each other. > > Then, you could also stop wondering what t

Re: generator/coroutine terminology

2015-03-16 Thread Marko Rauhamaa
Steven D'Aprano : > Marko Rauhamaa wrote: >> What features do generator iterators provide on top of generic >> iterators? > > The biggest difference is syntactic. Here's an iterator which returns a > never-ending sequence of squared numbers 1, 4, 9, 16, ... > > class Squares: > def __init__(se

Re: generator/coroutine terminology

2015-03-15 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: >>> Is it necessary/useful for a Python application programmer to be >>> conscious of the different types of iterator? What mistaken usage >>> could arise if the application just treated all iter

Re: generator/coroutine terminology

2015-03-15 Thread Steven D'Aprano
Rustom Mody wrote: > On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano > wrote: >> >> A generator (function) may be a function which returns an iterator,... > > I find "generator-function" misleading in the same way that "pineapple" > misleadingly suggests "apple that grows on

Re: generator/coroutine terminology

2015-03-14 Thread Rustom Mody
On Sunday, March 15, 2015 at 1:45:37 AM UTC+5:30, Ian wrote: > Now which should be considered definitive, the language reference or > the PEP? This question is not rhetorical; I don't know the answer. > Regardless of the answer though, the PEP at least illuminates the > design intent of the termino

Re: generator/coroutine terminology

2015-03-14 Thread Chris Angelico
On Sun, Mar 15, 2015 at 11:48 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 15, 2015 at 11:15 AM, Marko Rauhamaa wrote: >>> What features do generator iterators provide on top of generic >>> iterators? >> >> You can send values into them, throw exceptions into them, and close >> t

Re: generator/coroutine terminology

2015-03-14 Thread Marko Rauhamaa
Chris Angelico : > On Sun, Mar 15, 2015 at 11:15 AM, Marko Rauhamaa wrote: >> What features do generator iterators provide on top of generic >> iterators? > > You can send values into them, throw exceptions into them, and close > them (which is a special case of the latter). Hm. I wonder why the

Re: generator/coroutine terminology

2015-03-14 Thread Chris Angelico
On Sun, Mar 15, 2015 at 11:15 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: >>> Is it necessary/useful for a Python application programmer to be >>> conscious of the different types of iterator? What mistaken usage >>> could arise if the

Re: generator/coroutine terminology

2015-03-14 Thread Marko Rauhamaa
Chris Angelico : > On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: >> Is it necessary/useful for a Python application programmer to be >> conscious of the different types of iterator? What mistaken usage >> could arise if the application just treated all iterators as, well, >> iterators? >

Re: generator/coroutine terminology

2015-03-14 Thread Chris Angelico
On Sun, Mar 15, 2015 at 9:15 AM, Marko Rauhamaa wrote: > Oscar Benjamin : > >> A generator is a special type of iterator that results from generator >> functions and generator expressions. > > Is it necessary/useful for a Python application programmer to be > conscious of the different types of it

Re: generator/coroutine terminology

2015-03-14 Thread Marko Rauhamaa
Oscar Benjamin : > A generator is a special type of iterator that results from generator > functions and generator expressions. Is it necessary/useful for a Python application programmer to be conscious of the different types of iterator? What mistaken usage could arise if the application just tr

Re: generator/coroutine terminology

2015-03-14 Thread Oscar Benjamin
On 12 March 2015 at 16:52, Rustom Mody wrote: > > On Thursday, March 12, 2015 at 9:58:07 PM UTC+5:30, Steven D'Aprano wrote: >> Rustom Mody wrote: >> >> > >> > Say I have a simple yielding function: >> > >> > def foo(x): >> >yield x+1 >> >yield x+2 >> > >> > And I have >> > >> > g = foo(2)

Re: generator/coroutine terminology

2015-03-14 Thread Mark Lawrence
On 14/03/2015 20:14, Ian Kelly wrote: Now which should be considered definitive, the language reference or the PEP? This question is not rhetorical; I don't know the answer. Regardless of the answer though, the PEP at least illuminates the design intent of the terminology. The language refere

Re: generator/coroutine terminology

2015-03-14 Thread Ian Kelly
On Sat, Mar 14, 2015 at 1:54 AM, Marko Rauhamaa wrote: > Steven D'Aprano : > >> Marko Rauhamaa wrote: >> >>> Your 'factory' is a: >>> >>> generator >>> A function which returns an iterator. >>> https://docs.python.org/3/glossary.html> >> >> That glossary entry is misleading, or at

Re: generator/coroutine terminology

2015-03-14 Thread Rustom Mody
On Saturday, March 14, 2015 at 10:22:51 PM UTC+5:30, Chris Angelico wrote: > On Sun, Mar 15, 2015 at 3:33 AM, Rustom Mody wrote: > > As best as I can see python makes no distinction between such a foo and > > the more usual function/methods that have no returns. > > You can I can talk about these a

Re: generator/coroutine terminology

2015-03-14 Thread Dave Angel
On 03/14/2015 12:51 PM, Chris Angelico wrote: On Sun, Mar 15, 2015 at 3:33 AM, Rustom Mody wrote: As best as I can see python makes no distinction between such a foo and the more usual function/methods that have no returns. You can I can talk about these and distinguish them Python has no clue

Re: generator/coroutine terminology

2015-03-14 Thread Mark Lawrence
On 14/03/2015 16:33, Rustom Mody wrote: On Saturday, March 14, 2015 at 9:45:10 PM UTC+5:30, Chris Angelico wrote: On Sun, Mar 15, 2015 at 2:59 AM, Rustom Mody wrote: Causing all sorts of unnecessary confusions: An int-function returns int and a char*-functions returns char*. Does a void-functio

Re: generator/coroutine terminology

2015-03-14 Thread Chris Angelico
On Sun, Mar 15, 2015 at 3:33 AM, Rustom Mody wrote: > As best as I can see python makes no distinction between such a foo and > the more usual function/methods that have no returns. > You can I can talk about these and distinguish them > Python has no clue about it. But what support is actually n

Re: generator/coroutine terminology

2015-03-14 Thread Rustom Mody
On Saturday, March 14, 2015 at 9:45:10 PM UTC+5:30, Chris Angelico wrote: > On Sun, Mar 15, 2015 at 2:59 AM, Rustom Mody wrote: > > Causing all sorts of unnecessary confusions: > > An int-function returns int and a char*-functions returns char*. > > Does a void-function return void?? > > No a void

Re: generator/coroutine terminology

2015-03-14 Thread Chris Angelico
On Sun, Mar 15, 2015 at 2:59 AM, Rustom Mody wrote: > Causing all sorts of unnecessary confusions: > An int-function returns int and a char*-functions returns char*. > Does a void-function return void?? > No a void function doesn't return anything! > Ah So a void function does a longjmp? > > All o

Re: generator/coroutine terminology

2015-03-14 Thread Rustom Mody
On Saturday, March 14, 2015 at 8:59:22 PM UTC+5:30, Rustom Mody wrote: > On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano wrote: > > > > A generator (function) may be a function which returns an iterator,... > > I find "generator-function" misleading in the same way that "pine

Re: generator/coroutine terminology

2015-03-14 Thread Chris Angelico
On Sun, Mar 15, 2015 at 2:29 AM, Rustom Mody wrote: > However a "generator function" is a weird sort of function (at best). > Not regarding it as a function is IMO more reasonable. But it *is* a function. You call it, possibly with positional and/or keyword arguments, and you get back a returned

Re: generator/coroutine terminology

2015-03-14 Thread Rustom Mody
On Saturday, March 14, 2015 at 11:34:27 AM UTC+5:30, Steven D'Aprano wrote: > > A generator (function) may be a function which returns an iterator,... I find "generator-function" misleading in the same way that "pineapple" misleadingly suggests "apple that grows on pines" A builtin function is

Re: generator/coroutine terminology

2015-03-14 Thread Marko Rauhamaa
Mark Lawrence : > On 14/03/2015 07:54, Marko Rauhamaa wrote: >> I am an actual Python programmer (I develop Python programs) and my >> definitive source for Python is the documentation. If there is an >> error in the documentation, I would very much like it to be >> corrected. > > Five minutes wor

Re: generator/coroutine terminology

2015-03-14 Thread Mark Lawrence
On 14/03/2015 07:54, Marko Rauhamaa wrote: Steven D'Aprano : Marko Rauhamaa wrote: Your 'factory' is a: generator A function which returns an iterator. https://docs.python.org/3/glossary.html> That glossary entry is misleading, or at least incomplete, and it fails to mat

Re: generator/coroutine terminology

2015-03-14 Thread Marko Rauhamaa
Steven D'Aprano : > Marko Rauhamaa wrote: > >> Your 'factory' is a: >> >> generator >> A function which returns an iterator. >> https://docs.python.org/3/glossary.html> > > That glossary entry is misleading, or at least incomplete, and it > fails to match the way "generator" is us

Re: generator/coroutine terminology

2015-03-13 Thread Steven D'Aprano
Marko Rauhamaa wrote: > Your 'factory' is a: > > generator > A function which returns an iterator. > https://docs.python.org/3/glossary.html> That glossary entry is misleading, or at least incomplete, and it fails to match the way "generator" is used by actual Python programmers.

Re: generator/coroutine terminology

2015-03-13 Thread Chris Angelico
On Fri, Mar 13, 2015 at 8:12 PM, Rustom Mody wrote: > On Friday, March 13, 2015 at 1:53:50 PM UTC+5:30, Chris Angelico wrote: >> On Fri, Mar 13, 2015 at 4:28 PM, Rustom Mody wrote: >> > And even there I would expect generators to close with StopIteration >> > Whereas I would expect coroutines to

Re: generator/coroutine terminology

2015-03-13 Thread Marko Rauhamaa
Rustom Mody : > Nice demo of the same confusing terminology we are talking about. Why don't you just stick with the terminology of the language specification? I think your students are going to be more confused if you try to come up with something better. > When I say "expect generators to close

Re: generator/coroutine terminology

2015-03-13 Thread Rustom Mody
On Friday, March 13, 2015 at 1:53:50 PM UTC+5:30, Chris Angelico wrote: > On Fri, Mar 13, 2015 at 4:28 PM, Rustom Mody wrote: > > And even there I would expect generators to close with StopIteration > > Whereas I would expect coroutines to close (on close method) with > > GeneratorExit > > [Ive n

Re: generator/coroutine terminology

2015-03-13 Thread Chris Angelico
On Fri, Mar 13, 2015 at 4:28 PM, Rustom Mody wrote: > And even there I would expect generators to close with StopIteration > Whereas I would expect coroutines to close (on close method) with > GeneratorExit > [Ive not thought all this through properly so may be off the mark] I expect both of the

Re: generator/coroutine terminology

2015-03-12 Thread Rustom Mody
On Friday, March 13, 2015 at 9:00:17 AM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > On Thursday, March 12, 2015 at 11:25:32 PM UTC+5:30, Marko Rauhamaa wrote: > >> Rustom Mody : > >> > >> > I guess we need > >> > 1. A clear ontology of the base concepts (which is a buzzword for >

Re: generator/coroutine terminology

2015-03-12 Thread Steven D'Aprano
Rustom Mody wrote: > On Thursday, March 12, 2015 at 11:25:32 PM UTC+5:30, Marko Rauhamaa wrote: >> Rustom Mody : >> >> > I guess we need >> > 1. A clear ontology of the base concepts (which is a buzzword for >> > nailed-down terminology) >> >> According to the documentation, a function whose def

Re: generator/coroutine terminology

2015-03-12 Thread Rustom Mody
On Thursday, March 12, 2015 at 11:25:32 PM UTC+5:30, Marko Rauhamaa wrote: > Rustom Mody : > > > I guess we need > > 1. A clear ontology of the base concepts (which is a buzzword for > > nailed-down terminology) > > According to the documentation, a function whose definition contains a > yield st

Re: generator/coroutine terminology

2015-03-12 Thread Marko Rauhamaa
Terry Reedy : > On 3/12/2015 9:35 AM, Rustom Mody wrote: >> This is more a question about standard terminology/conventions than >> about semantics - of course assuming I understand :-) >> >> Say I have a simple yielding function: >> >> def foo(x): >> yield x+1 >> yield x+2 > > This is a ge

Re: generator/coroutine terminology

2015-03-12 Thread Terry Reedy
On 3/12/2015 9:35 AM, Rustom Mody wrote: This is more a question about standard terminology/conventions than about semantics - of course assuming I understand :-) Say I have a simple yielding function: def foo(x): yield x+1 yield x+2 This is a generator function And I have g = foo

Re: generator/coroutine terminology

2015-03-12 Thread Marko Rauhamaa
Rustom Mody : > I guess we need > 1. A clear ontology of the base concepts (which is a buzzword for > nailed-down terminology) According to the documentation, a function whose definition contains a yield statement is a generator: Using a yield expression in a function’s body causes that funct

Re: generator/coroutine terminology

2015-03-12 Thread Rustom Mody
Guess I should be pleased that I am doing as good as you (and Chris) describe. For some reason or not I am not... On Thursday, March 12, 2015 at 9:58:07 PM UTC+5:30, Steven D'Aprano wrote: > Rustom Mody wrote: > > > This is more a question about standard terminology/conventions than about > > sem

Re: generator/coroutine terminology

2015-03-12 Thread Steven D'Aprano
Rustom Mody wrote: > This is more a question about standard terminology/conventions than about > semantics - of course assuming I understand :-) > > Say I have a simple yielding function: > > def foo(x): >yield x+1 >yield x+2 > > And I have > > g = foo(2) > > If I look at type, g's ty

Re: generator/coroutine terminology

2015-03-12 Thread breamoreboy
On Thursday, March 12, 2015 at 1:35:48 PM UTC, Rustom Mody wrote: > This is more a question about standard terminology/conventions than about > semantics - of course assuming I understand :-) > > Say I have a simple yielding function: > > def foo(x): >yield x+1 >yield x+2 > > And I have

Re: generator/coroutine terminology

2015-03-12 Thread Chris Angelico
On Fri, Mar 13, 2015 at 12:35 AM, Rustom Mody wrote: > If I look at type, g's type is 'generator' whereas foo is just plain-ol > 'function.' > > Whereas in informal usage we say foo is a generator. > > So the question: > What should we call foo and what should we call g? g is a generator object;

generator/coroutine terminology

2015-03-12 Thread Rustom Mody
This is more a question about standard terminology/conventions than about semantics - of course assuming I understand :-) Say I have a simple yielding function: def foo(x): yield x+1 yield x+2 And I have g = foo(2) If I look at type, g's type is 'generator' whereas foo is just plain-ol