[Python-ideas] Anonymous blocks (again):

Juancarlo Añez apalala at gmail.com
Mon May 13 03:14:12 CEST 2013


Although I said I was over this never-ending topic, I thought I might say
that:

let:

    def block():
        # do stuff
in:
    closure(block)


Would be well understood by many in in the Python and functional-language
communities.

Cheers,


On Sun, May 12, 2013 at 7:43 PM, Martin Morrison <
martin.morrrison at cantab.net> wrote:

> On 13 May 2013, at 00:40, Nick Coghlan <ncoghlan at gmail.com> wrote:
>
> Now, do you have any constructive feedback on the PEP that still accounts
> for Python's lack of a standard location for passing callables to
> functions, or is this reaction simply a matter of "I don't want to have to
> type 'f' twice because I don't have to do that in other languages"?
>
> Moving past the outright negative feedback, and having only just seen the
> PEP, the proposed syntax did strike me as awkward and unintuitive. Maybe
> there is some explanation for why decorator-like syntax was used - if so,
> please do link me so I can read up.
>
> What struck me though is that the proposed syntax limits the ability to
> have multiple "anonymous blocks" within a single statement. Instead, I was
> thinking some syntax like the following might be nicer:
>
> in x = do_something(in_arg, success_hdlr, error_hdlr):
>     def success_hdlr(result):
>         ... # Do something with result
>     def error_hdlr(error):
>         ... # Do something with error
>
> That is instead of a decorator-like syntax, make the "in" keyword reusable
> to introduce a new block, whose "argument" is a statement that can forward
> reference some names, which are then defined within the block. This allows
> multiple temporary names to be defined (each in a separate statement within
> the block).
>
> Some further thought is required on whether only def (and maybe class)
> statements should be allowed within the "in" block. Although I guess
> there's technically nothing wrong with:
>
> in x = y + z:
>     y = 12
>     z = 30
>
> Other than it's a very verbose way of doing something simple. ;-) But
> maybe there are more useful examples?
>
> Cheers,
> Martin
>
> Regards,
> Nick.
>
>


-- 
Juancarlo *Añez*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130512/fca9c0b2/attachment.html>


More information about the Python-ideas mailing list