-
-
Notifications
You must be signed in to change notification settings - Fork 36
Clarify that variables declarations may override previous ones #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good generally, but a couple of comments (mainly editorial)
Also see #310 |
|
||
``` | ||
let $foo = {$foo :number minimumFractionDigits=2} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it's explained in the formatting doc, is it worth explaining here as well that in the third example, either there must be a previous in-scope definition of foo
, or this declaration is syntactically correct but semantically invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better example would make the second $foo
into $bar
or perhaps $someNumber
, since the point of examples is to demonstrate the syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aphillips Fair point. However, I'd like it if there was some place to put an example like this:
let $foo = {|5|}
let $foo = {$foo :number minimumFractionDigits=2}
{{$foo}}
It would be useful for explaining the meaning of variable resolution if the example said: "If this message resolves to a string, the string is '5.00'." That would show that the $foo
on the RHS on the second declaration is not the same as the $foo
on the LHS.
Probably the syntax.md
document isn't the place for that, since it doesn't show the resolved value of any of the examples.
Anyway, for illustrating the syntax, I'm OK with either or both.
I've rewritten the text, mostly based on language proposed by @aphillips and @catamorphism. Please re-review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be committed. I made one suggestion on wording and one suggestion for an addition (of what is, I believe, an unstated assumption)
spec/formatting.md
Outdated
If more than one _declaration_ binds a value to the same _name_, | ||
or if an externally defined variable and a _declaration_ use the same _name_, | ||
the resolved value of the most recent _declaration_ preceding the _variable_ is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also state that selectors and other post-declaration expressions can't modify a value (no non-declaration side-effects)?
I would suggest a slight wording change to make it easier (for me) to parse:
If more than one _declaration_ binds a value to the same _name_, | |
or if an externally defined variable and a _declaration_ use the same _name_, | |
the resolved value of the most recent _declaration_ preceding the _variable_ is used. | |
Each _declaration_ is processed sequentially: when a _declaration_ binds a value to a _name_ used in a previous _declaration_ or in an externally defined _variable_, | |
the resolved value of the most recent _declaration_ preceding the _variable_ is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the function purity / lack of side effects ought to be addressed with respect to function resolution, rather than here.
The proposed "is processed sequentially" statement is a bit problematic, as it may be interpreted to require and enforce an eager processing model. Consider this message:
let $foo = {:really-heavy-operation}
match {$bar}
when 0 {Nothing here}
when * {Have a {$foo}}
In this case, we should make sure that in the bar == 0
case an implementation is not required to determine and then throw away the value of $foo
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there is already an open issue about whether to require eager or lazy evaluation of local variables: #299
That said, I don't think either version of the wording commits to either eager or lazy evaluation. It depends on the interpretation of the word "processed". "Processing" could mean evaluating (resolving?) the right-hand side of the declaration and binding the left-hand side to the resulting value, or it could mean binding the left-hand side to a thunk representing the right-hand side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an ideal world, this would say something like "variables are lexically scoped". That would obviate the need to talk about the "most recent declaration". However, explaining what "lexical scope" means for messages would mean explaining that:
let $v1 = $e1
let $v2 = $e2
match ...
desugars to:
let $v1 = $e1 in
let $v2 = $e2 in
match ...
and that external definitions of variables desugar to let
s that enclose the message. I think that should be left for future work. I'm OK with merging the PR as-is; I think it's probably as precise as it's possible to get without mentioning lexical scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eemeli I don't think we have to say anything about early or late binding of variables: we should not require early binding but we should not require late binding either. It's an implementation detail. What is important is that declarations behave as if they were evaluated in order.
I think we can let the text go in as-is and revisit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote some comments, but I think those can mostly be addressed in future PRs. The only change I'd like to see before merging is the "overwrite"/"override" one.
spec/formatting.md
Outdated
If more than one _declaration_ binds a value to the same _name_, | ||
or if an externally defined variable and a _declaration_ use the same _name_, | ||
the resolved value of the most recent _declaration_ preceding the _variable_ is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an ideal world, this would say something like "variables are lexically scoped". That would obviate the need to talk about the "most recent declaration". However, explaining what "lexical scope" means for messages would mean explaining that:
let $v1 = $e1
let $v2 = $e2
match ...
desugars to:
let $v1 = $e1 in
let $v2 = $e2 in
match ...
and that external definitions of variables desugar to let
s that enclose the message. I think that should be left for future work. I'm OK with merging the PR as-is; I think it's probably as precise as it's possible to get without mentioning lexical scope.
|
||
``` | ||
let $foo = {$foo :number minimumFractionDigits=2} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aphillips Fair point. However, I'd like it if there was some place to put an example like this:
let $foo = {|5|}
let $foo = {$foo :number minimumFractionDigits=2}
{{$foo}}
It would be useful for explaining the meaning of variable resolution if the example said: "If this message resolves to a string, the string is '5.00'." That would show that the $foo
on the RHS on the second declaration is not the same as the $foo
on the LHS.
Probably the syntax.md
document isn't the place for that, since it doesn't show the resolved value of any of the examples.
Anyway, for illustrating the syntax, I'm OK with either or both.
Co-authored-by: Tim Chevalier <tjc@igalia.com>
or if an externally defined variable and a _declaration_ use the same _name_, | ||
the resolved value of the most recent _declaration_ preceding the _variable_ is used. | ||
|
||
A _declaration_ MAY override the value of a _variable_ for later parts of the _message_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that last time we proposed to not allow overriding.
Compared to programming, these messages are a relatively short "code block"
There should be no problem to just use a different name.
It just introduces complexity without any benefit that I can imagine.
Closing, as we did not reach consensus on this in the WG. The action is now on @mihnita and @catamorphism to champion an alternative PR. |
Naming things is hard, so we should make it as easy as possible. Specifically, I'm thinking here about the named parameters/arguments that a formatting call makes available within a message via variable references.
Let's say we have a numerical argument like
count
that we'd like to format using some set of options. That raw value will be initially represented as$count
within the message, but what about the value-with-formatter-and-options that we'd like to derive from it? Could that not also be$count
?To use a minimal example, I would like for something like this to be valid and have the obvious meaning:
This PR adds spec language and examples clarifying that this is valid.