a = b = 1 just syntactic sugar?

Martin v. Löwis martin at v.loewis.de
Sun Jun 8 19:14:31 EDT 2003


Ed Avis <ed at membled.com> writes:

> >That doesn't answer my question. What would be the output of this
> >statement?
> 
> It is syntactically ambiguous because of the two print statements both
> accepting commas.  

This still doesn't answer my question "What would be the output?",
since you say how you interpret the imagined output, but you don't say
what output you imagine.

I assume you want it to cause a SyntaxError.

Then the question is what algorithm exactly do you apply to detect an
ambiguity?

> >>Is it a rule of Python's grammar that no construct should ever require
> >>parenthesizing just to stop it being ambiguous?  
> >
> >No, there is no such rule.
> 
> So there is no reason to reject out of hand allowing one-line
> statements in lambda just because such constructs may require
> parenthesizing when used inside larger statements like 'print'.  

No, it is rejected because nobody has made a specification, yet, as to
how exactly it should work. Only if a precise, detailed, complete, and
implementable specification is made, it can be studied for undesired
effects, and possibly be rejected.

Actually, it doesn't need to be implementable - then we could reject
it for not being implementable.

> There may be other grammatical reasons of course.

Most likely. Without a precise, detailed, complete and implementable
spec, it is hard to tell what these reasons are.

> Elsewhere in this thread I have mentioned
> 
>     lambda_form ::=
>                  "lambda" [parameter_list]: simple_stmt
> 
> which seems to match the specification of 'any statement that can fit
> on one line' (which itself seems pretty exact to me).

Elsewhere in the thread I have said that this interpretation is
incorrect: a simple_stmt always ends with a NEWLINE, something which
you apparently don't want.

> >Then, if you have completed the specification, the problem likely is
> >that your proposed grammar is either counter-intuitive, or
> >unimplementable (depending on your specification).
> 
> Let's see which it is.

It's counter-intuitive that

x = (lambda s: print s)

is incorrect. Under your proposal, it would be incorrect, and you
would have to write

x = (lambda s: print s
)

to insert the necessary NEWLINE.

Regards,
Martin




More information about the Python-list mailing list