[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Code block function syntax, anonymous functions decorator

Aaron Brady

2/6/2008 8:55:00 PM

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.
2 Answers

Diez B. Roggisch

2/6/2008 10:59:00 PM

0

castironpi@gmail.com schrieb:
> 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

Aaron Brady

2/7/2008 5:07:00 AM

0

On Feb 6, 4:59 pm, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
> castiro...@gmail.com schrieb:
>
>
>
>
>
> > 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- 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.