[Python-ideas] For-loop variable scope: simultaneous possession and ingestion of cake
greg.ewing at canterbury.ac.nz
Thu Oct 9 01:30:11 CEST 2008
Jim Jewett wrote:
> How do you figure? As nearly as I can tell, the only difference is
> that let* is evaluated in order (left-to-right) instead of in
That's not quite right.
The difference between let and let* is that each expression
in a let* is evaluated in a scope that includes the names
bound by the previous expressions. In other words, it's
equivalent to a nested sequence of let statements.
> >>> def g(a=f(), b=h()): print b
> var is from f
> This shows that the side effect of binding a was already present when
> b was bound.
It's not about side effects, it's about name visibility.
If the binding of function arguments worked like let*,
then you would be able to refer to the name a in the
expression being assigned to b, i.e. this would be legal:
def g(a = f(), b = h(a)):
But it's not -- you would get a NameError on a if you
tried that. In that respect it's like let, not let*.
More information about the Python-ideas