[Python-ideas] Return expressions

Nathaniel Smith njs at pobox.com
Thu Nov 20 14:02:23 CET 2014


On Thu, Nov 20, 2014 at 10:01 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> >>> list(x for x in range(10) if x < 5 or return)
>  [0, 1, 2, 3, 4]

I'd be concerned about the confusion engendered by 'return' having
totally different semantics within very small regions, e.g. we'd have

def takewhile(iterable, pred):
    return (x for x in iterable if pred(x) or return)

Esp. because normally 'return' is very powerful -- right now any
mention of that token anywhere in a function body jumps out of the
entire function, so you really have to scan for them actively when
trying to understand a function's flow control.

Not a big fan of a flow control expression in general, really; yield
expressions are kinda flow-controlly, but they just pause execution,
they don't disrupt the logical through-line of a block of code.

-n

-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org


More information about the Python-ideas mailing list