> Can this lambda support multi-line expressions? If not, is there any hope of
> getting one that can?
The problem with multi-line lambda's in Python is:
How do you embed one in a function using INDENT/DEDENT syntax ?
( And remember my complaints about not being able to do:
"for x in seq : if f(x) : do_something" all on one line. )
There would need to be a explicit printable symbol for the INDEDENT/DEDENT
tokens. This might not be a bad idea, but I haven't thought it
Python's lambda is really just for the one-liners - to avoid the
annoyance of having to define a function just to increment:
new_sequence = map( lambda x: x+1, sequence )
I think the scoping problem that my previous post uncovered is
much MORE of a "killer" problem: It really makes lambda pretty
useless except from the top level __main__ scope.
> The one thing I've found that TCL is __REALLY__ good at, that no other
> language I've found matches, is extensions that have lots of callbacks.
> TCL's syntax exposes the view that an extension like expect, or the widgets
> of Tk, are nonlinear flow-of-control constructs.
> If Python had multi-line function call argument lists, where the arguments
> could be multi-line lambdas, I think it would achieve the same clarity. I
It's not clear to my how those callbacks are connected to lambda -
unless you just mean the convenience of writing them ( for example,
you don't have to def a print function for ftplib.retrlines() callback
since you can now use 'lambda s : print str' to turn the statement
print into a print function. )
You can still define a function and use it as a callback.
Is there some requirement for it to be anonymous that I don't
[ There are things in can complain about in BOTH Python's syntax AND
semantics - maybe I'm misreading you in connecting the two here?
Maybe "Dylan" will end up being not only a "better lisp", but a
"better Python" ... but I'm not going to hold my breath waiting
for an implementation! ]
Python CAN have multi-line function call argument lists -
>>> def f( a, b, c, d, e,
... g ):
... return a+b+c+d+e+g
>>> f( 1,2,3,4,5,6 )
>>> f( 1,2,
... 5,6 )
>>> def g( a, # comment
... b, # comment
... c # comment
... return a+b+c
They are also some kludges to make a def-ed function
semi-anonymous, but if you're after clarity, they are not
going to help you.
- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics