python and macros (again) [Was: python3: 'where' keyword]
Nick Coghlan
ncoghlan at iinet.net.au
Fri Jan 14 02:46:35 EST 2005
Paul Rubin wrote:
> Come on, that is vacuous. The claim was "expressions are not
> statements". But it turns out that expressions ARE statements. The
> explanation is "well, that's because they're expression statements".
> And there is no obvious case of an expression that can't be used as a
> statement. So it's not inherently obvious that there needs to be any
> kind of statement that can't be used as an expression. It's just an
> artifact. Whether the artifact is a desirable one is a matter of
> discussion.
No, it's entirely to do with building a readable language that uses significant
whitespace to delineate scope.
Simple statements are not allowed to contain other statements, but they are
allowed to contain expressions. In their most degenerate form, ALL they contain
is a *single* expression (e.g. a function call). That expression itself is still
not a statement, though. Think of it as the difference between value and [value].
Suites are sequences of statements.
Compound statements are statements which incorporate a suite as part of their
syntax.
Python allows statements inside suites and suites inside compound statements. It
also allows expressions inside statements and expressions inside expressions.
The one thing it never ever does is allow a suite or a statement inside an
expression, because doing so would utterly destroy the handling of significant
white space.
And that's why expressions are special in Python - they demarcate the boundary
of the significance of whitespace. Within an expression, whitespace is
insignificant. At the level of statements and suites, whitespace is extremely
significant.
So, precisely how should one go about cleanly embedding something that cares
about whitespace into a context which doesn't care in the slightest?
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list