Modula-3 says, in 2.6.15:
"Constant expressions are a subset of the general class of
expressions restricted by the requirement that it be possible to
evaluate the expression statically."
This could very easily be interpreted to mean any statically-evaluable
expression is a constant expression, but that would not be very
reasonable, does not seem to be what must have been meant, not what we
have.
Consider TRUE OR B, where B is a BOOLEAN variable. This can be
evaluated statically. So can many others:
V + 0
V * 1
V - V
MAX ( FIRST ( INTEGER ) , V )
MIN ( FIRST ( INTEGER ) , V )
These are relatively simple in involving very local analysis, but
we rapidly fall into a rabbit hole of algebra and probably
eventually undecidabilty:
( A + B ) - ( A - B )
Word . OR ( V , - 1 )
How about
( ORD ( A >= 0 ) * 2 - 1 ) A
IF A < 0 THEN
A + ABS ( A )
END (IF)
I propose that the language should say all operands of operations
in a constant expression must be constant expressions and that
FALSE, TRUE, NULL and all literals are constant expressions.
Does anybody have, know of, or wish to write any code that would
be undermined by this?
Modula-3 says, in 2.6.15:
"Constant expressions are a subset of the general class of
expressions restricted by the requirement that it be possible to
evaluate the expression statically."
This could very easily be interpreted to mean any statically-evaluable
expression is a constant expression, but that would not be very
reasonable, does not seem to be what must have been meant, not what we
have.
Consider TRUE OR B, where B is a BOOLEAN variable. This can be
evaluated statically. So can many others:
V + 0
V * 1
V - V
MAX ( FIRST ( INTEGER ) , V )
MIN ( FIRST ( INTEGER ) , V )
These are relatively simple in involving very local analysis, but
we rapidly fall into a rabbit hole of algebra and probably
eventually undecidabilty:
( A + B ) - ( A - B )
Word . OR ( V , - 1 )
How about
( ORD ( A >= 0 ) * 2 - 1 ) A
IF A < 0 THEN
A + ABS ( A )
END (IF)
I propose that the language should say all operands of operations
in a constant expression must be constant expressions and that
FALSE, TRUE, NULL and all literals are constant expressions.
Does anybody have, know of, or wish to write any code that would
be undermined by this?