469,610 Members | 2,081 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

Non-anonymous function arguments

I had an idea for passing functions as arguments:
Allow a block syntax (like with class definition)
for keyword arguments, attached to a statement
that includes a function call but doesn't need
the block for something else (like loops and ifs).
Apologies for the contrived examples.

squares = map(*):
def function(x): return x*x
list=[1,2,3]

def odds_and_evens(list, on_odd, on_even):
for i in list:
if (i % 2 == 0):
on_even(i)
else:
on_odd(i)

odds_and_evens([1,2,3,4,5],*):
def on_odd(i):
print (i/2) " * 2 + 1"
def on_even(i):
print "2 * " (i/2)

some_numbers=filter(*):
sequence=[1,2,3,4,5]
def function(x):
return x > 2

strange_list=sorted(["hello","world",7],*):
def key(x):
if (x==7):
return "SEVEN"
else:
return upper(x)

Unlike with lambda, the functions have names.
The marker inside the function call helps make
it obvious where the keywords go, especially
if the statement contains multiple function
calls.
There could be a keyword before the colon:

some_numbers=filter(*) using:
sequence=[1,2,3,4,5]
def function(x):
return x > 2

The marker is an asterisk because it's like
doing footnotes, alternatives are a plus sign
and multiple asterisks.
--
Caspian Maclean

Jul 19 '05 #1
0 771

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by lothar | last post: by
3 posts views Thread by Mario | last post: by
25 posts views Thread by Yves Glodt | last post: by
4 posts views Thread by bwmiller16 | last post: by
32 posts views Thread by Adrian Herscu | last post: by
14 posts views Thread by Patrick Kowalzick | last post: by
399 posts views Thread by =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post: by
12 posts views Thread by puzzlecracker | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.