Code block function syntax, anonymous functions decorator

C

castironpi

def run3( block ):
for _ in range( 3 ):
block()

run3():
normal_suite()

Introduces new syntax; arbitrary functions can follow 'colon'.

Maintains readability, meaning is consistent.

Equivalent to:

def run3( block ):
for _ in range( 3 ):
block()

@run3
def anonfunc():
normal_suite()

Simplification in cases in which decorators are use often.
 
D

Diez B. Roggisch

def run3( block ):
for _ in range( 3 ):
block()

run3():
normal_suite()

Introduces new syntax; arbitrary functions can follow 'colon'.

Maintains readability, meaning is consistent.

Equivalent to:

def run3( block ):
for _ in range( 3 ):
block()

@run3
def anonfunc():
normal_suite()

Simplification in cases in which decorators are use often.

This is non-sensical - how do you invoke anonfunc? They would all bind
to the same name, run3. Or to no name as all, as your "spec" lacks that.

Besides, it's butt-ugly IMHO. But taste comes after proper definition...

Diez
 
C

castironpi

(e-mail address removed) schrieb:













This is non-sensical - how do you invoke anonfunc? They would all bind
to the same name, run3. Or to no name as all, as your "spec" lacks that.

Besides, it's butt-ugly IMHO. But taste comes after proper definition...

Diez- Hide quoted text -

- Show quoted text -

The fallacy here is that @run3 as described is not a typical
decorator, such one that returns a function. It is called at
"definition"-time, that is, when the function definition is executed,
and executes the code.
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top