[Python-ideas] Reuse "for" to express "given"

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu May 24 12:22:09 EDT 2018


On Thu, May 24, 2018 at 12:04 PM Robert Vanden Eynde <robertve92 at gmail.com>
wrote:

> This idea was mentioned (by me) at a time yes, but wasn't written in the
document.

Can you point me to a specific post?  There were so may that I must have
missed that one.

> I think one of the thing was that it would make the grammar non LL1
because when seeing the token "for" in a list comprehension it wouldn't
know in advance if it's the loop or the assignment.

I don't see how that can be a problem.  From the grammar point of view,
"for" in "for var = <expr>" may still be seen as introducing a "loop", but
when "=" is seen in place of "in", the compiler will resize that the "loop"
is one a single value and emit efficient code for it.  At the AST level,
  "for var = <expr>"  will look exactly the same as  "for var in <expr>"
only with an "=" instead of "in".

> And also, it might confuse people because 'for' is for iteration.

I think I addressed this in my previous post.  Yes, for people with a C/C++
background, "for" may be too strongly associated with loops, but in
mathematical sense, it seems clear that "for var in a set" means iteration
over a set, while "for var = expression" means binding to a single value.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180524/89074427/attachment.html>


More information about the Python-ideas mailing list