Re: error in syntax description for comprehensions?

2017-03-30 Thread Terry Reedy

On 3/30/2017 4:57 PM, Boylan, Ross wrote:

https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries
describes the syntax for comprehensions as
comprehension ::=  expression comp_for
comp_for  ::=  [ASYNC] "for" target_list "in" or_test [comp_iter]
comp_iter ::=  comp_for | comp_if
comp_if   ::=  "if" expression_nocond [comp_iter]

Is the comp_for missing an argument after "in"?


The or_test *is* the 'argument'.


One has to follow the definition of or_test and its components,

> but I can't find anything that results to a single variable
> or expression.

An or_test *is* a single expression.  Like all python expressions, it 
evaluates to a python object.  In this case, the object is passed to 
iter() and so the object must be an iterable.


>>> a, b = None, range(3)
>>> a or b
range(0, 3)
>>> for i in a or b: print(i)

0
1
2

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: error in syntax description for comprehensions?

2017-03-30 Thread Ned Batchelder
On Thursday, March 30, 2017 at 4:59:03 PM UTC-4, Boylan, Ross wrote:
> https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries
> describes the syntax for comprehensions as
> comprehension ::=  expression comp_for
> comp_for  ::=  [ASYNC] "for" target_list "in" or_test [comp_iter]
> comp_iter ::=  comp_for | comp_if
> comp_if   ::=  "if" expression_nocond [comp_iter]
> 
> Is the comp_for missing an argument after "in"?
> One has to follow the definition of or_test and its components, but I can't 
> find anything that results to a single variable or expression.
> 
> Actually, I'm not sure what or_test would do there either with or  without an 
> additional element following "in". 


Syntax grammars can be obtuse. An or_test can be an and_test, which
can be a not_test, which can be a comparison.  It continues from there.
The whole chain of "can be" is:

or_test
and_test
not_test
comparison
or_expr
xor_expr
and_expr
shift_expr
a_expr
m_expr
u_expr
power
primary
atom
identifier

... and identifier is what you are looking for.

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


error in syntax description for comprehensions?

2017-03-30 Thread Boylan, Ross
https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries
describes the syntax for comprehensions as
comprehension ::=  expression comp_for
comp_for  ::=  [ASYNC] "for" target_list "in" or_test [comp_iter]
comp_iter ::=  comp_for | comp_if
comp_if   ::=  "if" expression_nocond [comp_iter]

Is the comp_for missing an argument after "in"?
One has to follow the definition of or_test and its components, but I can't 
find anything that results to a single variable or expression.

Actually, I'm not sure what or_test would do there either with or  without an 
additional element following "in". 

Ross Boylan
-- 
https://mail.python.org/mailman/listinfo/python-list