Non-anonymous function arguments

C

cjm_usenet

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,237
Messages
2,571,189
Members
47,825
Latest member
XCCMilo924

Latest Threads

Top