[Python-ideas] Anonymous blocks (again):

Juancarlo Añez apalala at gmail.com
Mon May 13 21:30:39 CEST 2013


On Mon, May 13, 2013 at 2:40 PM, Bruce Leban <bruce at leapyear.org> wrote:

> This is a much more common scenario than wanting anonymous blocks. I'm not
> proposing to change this. I'm just pointing out that if you're complaining
> about not being able to assign a value inside a statement, there are more
> common cases to look at.
>

I'm not complaining. I'm just pointing out that there may be more readable
ways to express things in Python than out-of-order.

I know that making def and class be expressions would cause enormous
problems. Because context managers are limited to their intended purpose, I
proposed new syntax that would provide for anonymous blocks in certain
places.

Instead of having to do:


def synthetic1():
     self.match('a')
     def synthetic2():
        self.match('b')
    self.closure(synthetic1)
self.closure(synthetic2)

Which is as close to cryptic as can bee, it could be:

within self.closure():

    self.match('a')
    within self.closure():

         self.match('b')


Which is, at least, in the right order. Adding the new keyword would allow
reusing the parsing for def:

within self.closure():
    def():

        self.match('a')
        within self.closure():
             def():

                  self.match('b')

So anonymous blocks can also take parameters, without the need to make def
an assignable expression.

Cheers,

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


More information about the Python-ideas mailing list