[Python-ideas] Special keyword denoting an infinite loop

Nick Coghlan ncoghlan at gmail.com
Sat Jun 28 17:14:53 CEST 2014


On 29 June 2014 00:56, Benny Khoo <benny_khoo_99 at yahoo.com> wrote:
> rather than a special keyword in Python, how about having Python to support
> the concept of passing block (a group of statements) as argument? I thought
> that can be quite elegant solution. So a loop statement can be interpreted
> simply as a function that accept a block e.g. loop [block]?
>
> Supporting block has a lot of practical applications. I remember seeing some
> special purpose flow control functions as early as Tcl. We also see it in
> Ruby and the more recently the new Swift language.

This is a well worn path, and it's difficult to retrofit to an
existing language. Ruby, at least, relies heavily on a convention of
taking blocks as the last argument to a function to make things work,
which is a poor fit to Python's keyword arguments and far more varied
positional signatures for higher order functions.

PEP 403 and PEP 3150 are a couple of different explorations of the
idea a more block-like feature.
http://python-notes.curiousefficiency.org/en/latest/pep_ideas/suite_expr.html
is one that goes even further to consider a delineated subsyntax for
Python that would allow entire suites as expressions.

However, the stumbling block all these proposals tend to hit is that
proponents really, really, struggle to come up with compelling use
cases where "just define a named function" isn't a clearer and easier
to understand answer.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list