Let's Talk About Lambda Functions!

John Roth johnroth at ameritech.net
Sat Aug 3 17:12:17 EDT 2002


"Huaiyu Zhu" <huaiyu at gauss.almadan.ibm.com> wrote in message
news:slrnakme8c.bn9.huaiyu at gauss.almadan.ibm.com...
> Bengt Richter <bokr at oz.net> wrote:
> >Just leave out the name after the def to make it anonymous,
> >and use parens to make the scope of the def expression obvious, e.g.,
> >
> >    x = y + (
> >        def (z):
> >            if z: return 'True z'
> >            else: return 'False z'
> >        )('arg for anonymous function') + ' & additional expression
terms.'
> >
>
> One problem of allowing intervening parens to adjust indentation is
that the
> following is also a possibility
>
>     x = y + (
> def (z):
>     if z: return 'True z'
>     else: return 'False z'
>         )('arg for anonymous function') + ' & additional expression
terms.'

As Bengt points out at more depth, this would be a syntax error,
because there is no dedent following the function. The next line after
the
else must be at the same or to the left of the def, which puts it to the
left of the expression, which is a syntax error.

The only way of making it not a syntax error is to indent reasonably.

John Roth






More information about the Python-list mailing list