python and macros (again) [Was: python3: 'where' keyword]
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Fri Jan 14 13:33:05 EST 2005
Antoon Pardon wrote:
> 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.
True, I wanted to add that but forgot it. Doesn't change what I'm saying
though.
> 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.
In both cases we have an expression, in both cases we have a statement,
in both cases the expression is a part of the statement. In one case the
expression is the only statement, in the other case the statement has
other parts too.
>
>>Note that it would be perfectly possible to modify the syntax into
>>
>>expression_stmt ::= "exprstmt" expression_list
>>...
>
> 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?
No, you still have a statement with one or more parts, one of which is
an expression.
In OOP terms: I think that an expression statement 'has an' expression
(I agree that is a very thin wrapper though), not that an expression
statement 'is an' expression.
>>>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.
Whether statements can be used in the place of expressions is indeed not
relevant to the discussion.
Regarding what Guido apparently said:
Op 2005-01-12, Steve Holden schreef <steve at holdenweb.com>:
>> Given that Guido is on record as saying that expressions aren't
>> statements because he wants those things to be separate
Antoon Pardon wrote:
> Well, it seems that Guido is wrong then. The documentation clearly
> states that an expression is a statement.
I don't think it says that at all.
> More specifically, everywhere you can use a statement, you can
> simply use an expression according to the python syntax.
If you use an expression where a statement is expected, you really
write an expression statement that contains the expression (and nothing
else, but that doesn't matter).
--
"Codito ergo sum"
Roel Schroeven
More information about the Python-list
mailing list