Re: Feature request: subclassing FunctionType [Was: Some languageproposals]

From: Terry Reedy (tjreedy_at_udel.edu)
Date: 03/02/04


Date: Tue, 2 Mar 2004 10:29:53 -0500
To: python-list@python.org


"Michele Simionato" <michele.simionato@poste.it> wrote in message
news:95aa1afa.0403012224.506dd07c@posting.google.com...
> 1. Assuming all "for" loops and list comprehensions are replaced
> with Haskell bindings rules, what about backward compatibility
> problems? For instance: is there enough code relying on the loop
> variable being available outside the loop?

Guido has given things like the following as an intentional reason for the
current rule (and for for...else):

for item in seq:
  if acceptable(item): break
else:
  item = None
# item is now either the first acceptible item in seq or None

If you do not like the iteration var remaining bound, you can explicitly
delete it. If it is automatically deleted, constructions like the above
are rendered more difficult.

A list comp encapulates a specialized for loop whose specific job is to
produce a list. It makes more sense to delete the binding automatically
there since a) there is no way, when seq is empty, to force a binding to
*something*, with else and b) the last item of the list is readily
available anyway as result[-1].

Terry J. Reedy



Relevant Pages

  • Re: The Lisp CPU
    ... If profiling shows there's a tight loop ... Because you're using dynamic binding, ... and re-bind them all with the most-crucial ...
    (comp.lang.lisp)
  • Re: DataTable Processing
    ... talking about binding, XML, or other things above and beyond what I ... > Use the DataTable.Select method to return an array of DataRows. ... > can loop through the array. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Can I manually add items to a repeater after binding it?
    ... .NewRows as needed to fill in the holes before binding. ... LIfe will be easier if you loop from the bottom to the top, since you won't need to worry about jumping over the new rows as you insert them. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: assignment in a for loop
    ... what looks like "assignment" really is binding a name to an ... The result is that inside the loop I am creating an object ... You can also do it more succinctly with a list comprehension ...
    (comp.lang.python)