PEP 255: Simple Generators

Tim Peters tim.one at home.com
Wed Jun 27 20:34:50 CEST 2001


[Carsten Geckeler]
> ...
> Do you really mean that?  I would not start teaching Icon generators in
> the context of simple looping like in
>
> every i:= 1 to 10
> do write(i)

Griswold does.  In the 3rd edtion of "The Icon Programming Language", the
first two examples of generators are

    every i := find(s1, s2) do write(i)

and

    every i := 1 to limit do write(i^2)

immediately contracted to

    every write((1 to limit)^2)

>> except that Icon also has many other kinds of "special context"
>> shere generators act reasonably.

> This other "special context" of expressions failing and fallback is
> acutally the core idea of Icon.

Alternation and conjunction are also explicit generative control structures,
distinct from the "every" and "suspend" generative control structures; I
assume you lump them in with "expressions", but it's really subtler than
that.  In a similar way, "and" and "or" are really more control structures
in Python than operators.  Expression evaluation in Icon also invokes
conjunction implicitly all over the place, but not across statements, or
across the X and Y in "every X do Y", etc.

> Probably most of the readers of this list are not really familiar
> with Icon, so some examples may be useful.

That's fine, but I'm going to skip it as the relationship to the PEP is
getting too thin:  PEP 255 isn't aiming at goal-directed evaluation, just at
generators.





More information about the Python-list mailing list