Code block function syntax, anonymous functions decorator
castironpi at gmail.com
castironpi at gmail.com
Fri Feb 8 21:15:35 EST 2008
On Feb 8, 1:08 am, Arnaud Delobelle <arno... at googlemail.com> wrote:
> On Feb 8, 6:50 am, castiro... at gmail.com wrote:
>
>
>
>
>
> > Sometimes, it's more appropriate to write
>
> > @call
> > def f():
> > normal_suite()
>
> > than
>
> > def f():
> > normal_suite()
> > f().
>
> > It's clearer to the eye and reader, and truer to the meaning of the
> > code. From reading the docs, it's pretty clear that it's not what the
> > author meant for decorators. So, even though it's good and practical,
> > as well as Pythonic, it doesn't get in.
>
> As I remarked in a recent post, it's already almost in, but it's
> called '@apply' (I don't know what your @call returns):
>
> @apply
> def the_answer(x=6):
> return x*(x+1)
>
> print the_answer
>
> :-)
>
> --
> Arnaud- Hide quoted text -
>
> - Show quoted text -
Python 3.0a2 (r30a2:59405M, Dec 7 2007
>>> apply
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'apply' is not defined
I understand it's "To be removed" [1]. These proposals are similar
[2] [3].
What is not in is a full-fledged anonymous function. That is a code
block.
I personally have been focussing on multi-threading, looking to the
future, so forgive the one-sided example.
@start_new_thread
def anonA():
normal_suite()
Similar.
start_new_thread():
normal_suite()
Or, if you're using other arguments, or the function does not take a
function as its first parameter, rearrange parameters with a standard
function.
Makes it hard to join or call if you ever need it more than once. I
don't believe that assigning the return to a name fits in with the
grand scheme.
Yes:
def convenientstart( func ):
Thread( target= func ).start()
@convenientstart
def anonA():
normal_suite()
Yes:
def convenientstart( func ):
th= Thread( target= func, args= ( th, ) )
th.start()
return th#, but where does it go?
convenientstart():
normal_suite()
No:
def convenientstart( func ):
Thread( target= func ).start()
convenientstart() as thA:
normal_suite()
I dream:
def convenientstart( func, A ):
th= Thread( target= func, args= ( th, A ) )
th.start()
return th#, but where does it go?
th= convenientstart( A ):
normal_suite()
Cf. bound object instance calls: code block is the applicable "self".
Another day, perhaps.
I am extremely open to feedback. Asking to brainstorm. Thoughts
welcome. Any?
[1] http://www.python.org/dev/peps/pep-3100/ .
[2] http://mail.python.org/pipermail/python-ideas/2007-October/001083.html
[3] http://mail.python.org/pipermail/python-ideas/2007-October/001086.html
More information about the Python-list
mailing list