[Python-ideas] Anonymous blocks (again):

David Mertz mertz at gnosis.cx
Mon May 13 03:04:17 CEST 2013


On Sun, May 12, 2013 at 5:30 PM, Martin Morrison <mm at ensoft.co.uk> wrote:

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

I just read PEP 403 myself also.  I confess I likewise have trouble getting
past the unnatural feeling (to me, at least at first brush) of the
decorator syntax.  The rejected alternative of the 'given' keyword seems
less unnatural.

I wonder though why not just use the ML style here.  E.g. Spell this:


> 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
>

As:

in x = do_something(in_arg, success_hdlr, error_hdlr, const) let:
>     def success_hdlr(result):
>         ... # Do something with result
>     def error_hdlr(error):
>         ... # Do something with error
>     const = 42
>

Well, I've reversed the order of in/let from ML, but the keywords are the
same.  But as Martin points out, I can't see any reason to preclude
defining multiple one-off blocks... not even if the name definitions aren't
'def' or 'class' (hence my addition of defining 'const=42' in my slightly
expanded version).

Yes it's still a pseudo-block, and we do have to do something with
scoping.  But it reads better to me than 'given', and also better than the
bare 'in' block introduction without the explicit 'let'.

Yours, David...

-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130512/1f02d517/attachment.html>


More information about the Python-ideas mailing list