python and macros (again) [Was: python3: 'where' keyword]

Antoon Pardon apardon at forel.vub.ac.be
Fri Jan 14 17:51:32 CET 2005


Op 2005-01-14, Roel Schroeven schreef <rschroev_nospam_ml at fastmail.fm>:
> Antoon Pardon wrote:
>> IMO we have a: dogs are mamals kind of relationship in Python.
>
> I see what you mean, but I don't think it's true.
>
>> Every expression can be used where a statement is expected.
>> (And this can be worded as: every expression is a statement.)
>
> Not really. An expression statement is a statement that looks like an 
> expression, but actually it's more than that: not only does it calculate 
> the value of the expression, it also prints the value.

1) Only in an interactive environment.

2) That the semantics differ according to where the expression is
   used doesn't make a difference. That an expression decides which
   branch of an if statement is executed or what object is pass
   as an argument in a call are also semantic difference, yet 
   we still have an expression in both cases.

> Note that it would be perfectly possible to modify the syntax into
>
> expression_stmt ::= "exprstmt" expression_list
>
> so that you would have to write
>
> exprstmt 6*9
>
> instead of just
>
> 6*9
>
> That makes it clearer to see the distinction: 6*9 is an expression,
>
> exprstmt 6*9
>
> is a statement. An expression statement, more precisely.

If you change the syntax, of course you will change the strings
that will be accepted. I could change the syntax to:

  if_stmt ::= "if" "ifexpr" expression ...

Have I now proved that expressions after an if are not normal
expressions?

>
>> Not every statement can be used where an expression is expected. 
>
> AFAIK *no* statement can be used where an expression is expected.

But that was not the implication of what Guido supposedly had said.
So that this is not the case doesn't counter what I said.

-- 
Antoon Pardon



More information about the Python-list mailing list