Why not all statement are expressions ?

Stewart Gordon smjg_1998 at yahoo.com
Sun Jul 15 10:56:53 PDT 2012


On 07/05/2012 21:27, Nick Sabalausky wrote:
<snip>
> I'm usually fairly ambivalent about the idea of statements being
> expressions, but I would *love* for switch to be usable as an expression.
<snip>

Switch cases are sequences of statements.  Allowing them to alternatively be expressions 
would create ambiguity in the grammar.

If you're designing a language and want switch expressions as well as switch statements, 
then don't try to make one look like the other.  For example, C didn't try to make 
conditional expressions look like if statements - it created a new syntax for conditional 
expressions.

That said, it's possible to design a language to have no distinction between expressions 
and statements.  But you can't really conflate the two syntaxes in an existing language.

Of course, D could have been designed as such a language.  But it wasn't.  It was designed 
to have the same overall look and feel as C.

Stewart.


More information about the Digitalmars-d mailing list