Anonymus functions revisited

Claudio Grondi claudio.grondi at freenet.de
Tue Mar 22 13:47:28 CET 2005


> > Already
> >   lambda x,y,z=0:(x,y,z)
> > is a problem for me.
> >
> > Why not:
> > try:
> >   (x,y,z)
> > except NameError:
> >   z=0
> >   (x,y,z)
> > ?
>
> Because they are not equivallent.
>
> > Watching the last piece of code
> > can even directly be seen, that there
> > is eventually a NameError
> > problem with z to handle,
>
> And suppose there is a NameError with x,
> your piece of code will then assign 0 to
> z. Do you think that is what the original
> code wanted?
Ok, I see.
But inspite of the fact, that I have
overseen this while writing the
code, this bad assignment won't
much matter, because the script will fail
anyway in (x,y,z), so there will be no
effect on the subsequent code.

If  I had written:
try:
  z
except NameError:
  z=0
#:try/except
(x,y,z)
I would be closer to the original
idea behind
lambda x,y,z=0:(x,y,z)
right?

> > [lambda] It is usable as an argument.
I have to admit, that I still don't understand
the concept behind lambda, because this
construct in new to me. Maybe it is because
I still haven't seen any example making it
clear, why lambda is the only or at least
the better way to go.

Even if I am very interested in understanding
and discussing lambda related matters here,
I see, that with discussing it we are probably
far away from the original intent of Kay who
expects in this thread postings expressing
an opinion about introduction of the
   (x,y,z=0) -> (x,y,z)
construct in Python.

Claudio





More information about the Python-list mailing list