Mailing List Archive

return statements in lambda
from "Python for Lisp Programmers":
http://www.norvig.com/python-lisp.html

> Don't forget return. Writing def twice(x): x+x is tempting
> and doesn't signal a warning or > ception, but you probably
> meant to have a return in there. This is particularly irksome
> because in a lambda you are prohibited from writing return,
> but the semantics is to do the return.

maybe adding an (optional but encouraged) "return"
to lambda would be an improvement?

lambda x: x + 10

vs.

lambda x: return x + 10

or is this just more confusing... opinions?

</F>
RE: return statements in lambda [ In reply to ]
[/F]
> maybe adding an (optional but encouraged) "return"
> to lambda would be an improvement?
>
> lambda x: x + 10
>
> vs.
>
> lambda x: return x + 10
>
> or is this just more confusing... opinions?

It was an odd complaint to begin with, since Lisp-heads aren't used to using
"return" anyway. More of a symptom of taking a shallow syntactic approach
to a new (to them) language.

For non-Lisp heads, I think it's more confusing in the end, blurring the
distinction between stmts and expressions ("the body of a lambda must be an
expression" ... "ok, i lied, unless it's a 'return' stmt). If Guido had it
to do over again, I vote he rejects the original patch <wink>. Short of
that, would have been better if the lambda arglist required parens, and if
the body were required to be a single return stmt (that would sure end the
"lambda x: print x" FAQ -- few would *expect* "return print x" to work!).

hindsight-is-great<wink>-ly y'rs - tim