Re: Is there a better/simpler way to filter blank lines?



On Wed, 05 Nov 2008 14:39:36 +1100, Ben Finney wrote:

Marc 'BlackJack' Rintsch <bj_666@xxxxxxx> writes:

On Wed, 05 Nov 2008 13:18:27 +1100, Ben Finney wrote:

Marc 'BlackJack' Rintsch <bj_666@xxxxxxx> writes:

Your example shows only that they're important for grouping the
expression from surrounding syntax. As I said.

They are *not* important for making the expresison be a generator
expression in the first place. Parentheses are irrelevant for the
generator expression syntax.

Okay, technically correct but parenthesis belong to generator
expressions because they have to be there to separate them from
surrounding syntax with the exception when there are already enclosing
parentheses. So parenthesis are tied to generator expression syntax.

No, I think that's factually wrong *and* confusing.

>>> list(i + 7 for i in range(10))
[7, 8, 9, 10, 11, 12, 13, 14, 15, 16]

Does this demonstrate that parentheses are “tied to” integer literal
syntax? No.

You can use integer literals without parenthesis, like the 7 above, but
you can't use generator expressions without them. They are always
there. In that way parenthesis are tied to generator expressions.

If I see the pattern ``f(x) for x in obj if c(x)`` I look if it is
enclosed in parenthesis or brackets to decide if it is a list
comprehension or a generator expression. That may not reflect the formal
grammar, but it is IMHO the easiest and pragmatic way to look at this as
a human programmer.

Ciao,
Marc 'BlackJack' Rintsch
.



Relevant Pages

  • Re: Is there a better/simpler way to filter blank lines?
    ... expression from surrounding syntax. ... surrounding syntax with the exception when there are already enclosing ...  So parenthesis are tied to generator expression syntax.. ...
    (comp.lang.python)
  • Re: Confusion with bindings - scheme newbie
    ... the syntax of LET is ... a LET that has only one binding looks like ... [(sos y z)] ... Now thats a lot of parenthesis to deal with. ...
    (comp.lang.scheme)
  • Re: ksh function names
    ... The syntax with or without parenthesis makes it work differently, ... >> myfunc() ... but in recent ksh versions it returns the global script ...
    (AIX-L)
  • Re: About those parenthesis....
    ... > I like parenthesis and prefix from beginning. ... I have programmed with Lisp-like semantics using the fsyntax. ... The fnotation has no nice way to denote the empty list, ... So, in summary, fis an abomination that rightfully deserves ...
    (comp.lang.lisp)
  • Re: print(true and true) #=> the parenthesis issue
    ... The parenthesis have been discussed before, ... out why the parser gets confused here. ... In the second case the parser seems to be expecting ... obscure syntax that requires this behavior. ...
    (comp.lang.ruby)