[Sorry, I accidentally set the Reply-To incorrectly in my previous msg;
corrected here. I don't need a CC in responses.]
* Jan Mercl <
0xj...@gmail.com> [220318 12:04]:
If you had included the above quote in your original response, I would
have agreed with you. However, your other msg only contained a
playground link that demonstrated that the compiler believed the
expression to be non-constant without giving any explanation of why that
was correct according to the spec.
Axel's original response clearly explained why the spec mandated the
behavior that the OP was questioning.
On the other hand, Axel's response left me wondering why the part of the
spec he quoted was written the way it was, while your quote above at
least superficially justifies the parts of the spec Axel quoted which I
was questioning; thanks.
My question stems from the fact that
var a = [3]{1, 2, f()}
const x = len(a)
compiles with the obvious results, but
const x = len([3]{1, 2, f()})
does not compile. I.e. the value obtained from evaluating a composite
literal expression of array type has a constant length, so why is taking
the len() of that value different from assigning that value to a
variable and then taking the len() of the variable?
I was really looking for the language designers to chime in with a
justification, but I guess I can accept "we don't want constant
expressions to be allowed to have side effects" as the answer.
...Marvin