Shane Hathaway wrote:
John Roth wrote:
I would write it this way:
result = map(def(x, y, z), list1, list2, list3):
something
something else
return x
Shane
What do you do if the expression is in an "if" statement?If you can make a contribution to a good syntax for
a code block, I for one would welcome it.
Just to give you a start: Ruby puts a single code block
at the end of the parameter list where it's quite obvious
what it is and where it does not interrupt the flow of reading
the method call. In python, I'd like to be able to put code
blocks wherever I can currently put a function / method
object.
For example:
result = map(lambda: ..., list1, list2, list3)
is readable - barely.
result = map(def (x, y, z):
something
something else
return
list1, list2, list3)
becomes much less readable. This is the problem that
needs to be solved to make code blocks fly.
That's one of the things I'm trying to achieve, too. Using this syntax,a code block, I for one would welcome it.
Just to give you a start: Ruby puts a single code block
at the end of the parameter list where it's quite obvious
what it is and where it does not interrupt the flow of reading
the method call. In python, I'd like to be able to put code
blocks wherever I can currently put a function / method
object.
For example:
result = map(lambda: ..., list1, list2, list3)
is readable - barely.
result = map(def (x, y, z):
something
something else
return
list1, list2, list3)
becomes much less readable. This is the problem that
needs to be solved to make code blocks fly.
I would write it this way:
result = map(def(x, y, z), list1, list2, list3):
something
something else
return x
Shane
if map(def(x,y,z),list1,list2,list3):
# what goes here? The body of the function
# or the body of the if? And how does the rest of it
# look?
Also, limiting to "one per expression" prevents you from doing something
like:
myHandlers = {
"click" : def(x,y):
print "click at x,y"
"enter" : def():
print "mouse entered"
"exit" : def():
print "mouse exited"
}
(since you'd have to write:
myHandlers = {
"click" : def(x,y),
"enter" : somePreviousFunctionForEnter,
"exit" : somePreviousFunctionForExit
} :
print "click at x,y"
which, due to the large distance between the "def" and the body is
terribly hard to figure out)