-
Notifications
You must be signed in to change notification settings - Fork 106
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
Editorial: Define a structured signature for PluralRuleSelect #594
Editorial: Define a structured signature for PluralRuleSelect #594
Conversation
spec/datetimeformat.html
Outdated
@@ -374,7 +374,7 @@ <h1>FormatDateTimePattern ( _dateTimeFormat_, _patternParts_, _x_, _rangeFormatO | |||
1. Else if _p_ is equal to *"timeZoneName"*, then | |||
1. Let _f_ be _dateTimeFormat_.[[TimeZoneName]]. | |||
1. Let _v_ be _dateTimeFormat_.[[TimeZone]]. | |||
1. Let _fv_ be a String value representing _v_ in the form given by _f_; the String value depends upon the implementation and the effective locale. The String value may also depend on the value of the [[InDST]] field of _tm_. If the implementation does not have a localized representation of _f_, then use the String value of _v_ itself. | |||
1. Let _fv_ be a String value representing _v_ in the form given by _f_; the String value depends upon the implementation and the effective locale. The String value may also depend on the value of the [[InDST]] field of _tm_. If the implementation does not have a localized representation of _f_, then use the String value of _v_ itself. |
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 removal of consecutive whitespace resolves a warning from ecmarkup.
spec/pluralrules.html
Outdated
<emu-clause id="sec-pluralruleselect" type="implementation-defined abstract operation"> | ||
<h1> | ||
PluralRuleSelect ( | ||
_locale_: a String, | ||
_type_: a String, | ||
_n_: a finite Number, | ||
_operands_: a Plural Rules Operands Record corresponding with _n_, | ||
) | ||
</h1> | ||
<dl class="header"> |
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.
Further adoption of structured operation headers can be accomplished later.
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 assume this is a new convention from ECMA-262? It looks great, thanks!
spec/pluralrules.html
Outdated
</h1> | ||
<dl class="header"> | ||
<dt>description</dt> | ||
<dd>It returns the String from « *"zero"*, *"one"*, *"two"*, *"few"*, *"many"*, *"other"* » that best categorizes _n_ according to the rules for _locale_ and _type_.</dd> |
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 operands doesn't actually seem relevant to the signature of PluralRuleSelect... I'd like to take this PR even further, removing locale, type, and operands and replacing them with a single pluralRules argument (an instance with an [[InitializedPluralRules]] slot) for better comprehensibility and alignment with other parts of the spec, in the process also removing GetOperands as an implementation detail (since its only use is to construct operands).
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.
Thanks! Once this is merged I'll pull it in to NFv3.
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.
LGTM. Not sure if the follow-on change you mentioned will keep this PR editorial or not... @sffc @zbraniecki what do you think?
<p> | ||
When the PluralRuleSelect abstract operation is called with four arguments, it performs an implementation-dependent algorithm to map _n_ to the appropriate plural representation of the Plural Rules Operands Record _operands_ by selecting the rules denoted by _type_ for the corresponding _locale_, or the String value *"other"*. | ||
</p> | ||
<emu-clause id="sec-pluralruleselect" type="implementation-defined abstract operation"> |
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.
The aoid
is gone, I suppose automagic linking of this AO from algorithms won't work anymore.
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.
aoid
is now pulled from the structured header, cf. https://github.com/tc39/ecmarkup/blob/6253fe32dec8a8b7f4271e76f734fbab2ee4c5f4/src/Clause.ts#L122-L143
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.
oh wow, this is great. I should really keep up with all the exciting new stuff in ecmarkup
spec/pluralrules.html
Outdated
<emu-clause id="sec-pluralruleselect" type="implementation-defined abstract operation"> | ||
<h1> | ||
PluralRuleSelect ( | ||
_locale_: a String, | ||
_type_: a String, | ||
_n_: a finite Number, | ||
_operands_: a Plural Rules Operands Record corresponding with _n_, | ||
) | ||
</h1> | ||
<dl class="header"> |
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 assume this is a new convention from ECMA-262? It looks great, thanks!
I believe it would because PluralRuleSelect is called only from ResolvePlural, which pulls locale and type directly from slots on pluralRules and determines operands by invoking GetOperands on a value from the response of FormatNumericToString(pluralRules, n). So if PluralRuleSelect were provided with pluralRules and n similar to e.g. FormatDateTime(dateTimeFormat, x) and FormatNumeric(numberFormat, x), then it could do those steps itself (reading [[Locale]] and [[Type]] and determining how they affect the result of "zero" vs. "one" vs. "two" vs. "few" vs. "many" vs. "other"). Unless there's some reason why the internal behavior of plural rule selection MUST format the number to a numeric string and then use the resulting integer/fraction digit counts to make its determination, even though that determination is itself implementation-defined? |
The number is formatted as a string, because plural rules make a difference between integers and non-integers: js> new Intl.PluralRules("en", {minimumFractionDigits: 0}).select(1)
"one"
js> new Intl.PluralRules("en", {minimumFractionDigits: 2}).select(1)
"other" And by specifying that |
I just don't see how that's the case... non-normative references to CLDR and in-spec examples would help much more than requiring a roundabout trip from Number to String to Record—especially when the Record appears to be an attempt to recover integer/fraction/significant digits configuration that already exists on pluralRules. The current algorithm seems overly prescriptive, and rather divergent from other parts of the spec. Maybe what's putting me off is that PluralRuleSelect has access to n in addition to the Record derived from inspecting its string serialization subject to pluralRules, but does not have access to pluralRules itself... it seems so strange to provide both n and operands. |
spec/pluralrules.html
Outdated
@@ -79,35 +75,42 @@ <h1>GetOperands ( _s_ )</h1> | |||
<td>Number of digits of [[Number]].</td> |
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.
@sffc there are problems with the definitions of these fields:
- [[IntegerDigits]] is defined as "Number of digits of [[Number]]", but is populated with the number value of the integer digits (e.g., it is equal to 8 for an input string like "8.540").
- [[FractionDigits]] and [[NumberOfFractionDigits]] have effectively the same definition, even though the former is populated with the number value of the fractional digits while the latter is populated with the count of such digits (e.g., they are respectively equal to 540 and 3 for an input string like "8.540").
- [[FractionDigitsWithoutTrailing]] and [[NumberOfFractionDigitsWithoutTrailing]] also have effectively the same definition, even though the former is populated with the number value of the truncated fractional digits while the latter is populated with the count of such digits (e.g., they are respectively equal to 54 and 2 for an input string like "8.540").
I'd like to fix this... do you know what the actual intent is?
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 these are supposed to correspond to: https://unicode.org/reports/tr35/tr35-numbers.html#Operands
- i | integer digits of n.
- v | number of visible fraction digits in n, with trailing zeros.*
- w | number of visible fraction digits in n, without trailing zeros.*
- f | visible fraction digits in n, with trailing zeros.*
- t | visible fraction digits in n, without trailing zeros.*
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.
Thanks. I added references and updated the text to match (which is still just editorial work).
Concrete proposal: drop GetOperands and change the signature of PluralRuleSelect to accept a String ([[FormattedString]] output from FormatNumericToString) rather than a Number and a Record. The string parsing of GetOperands would become an implementation detail, but the implementation-defined behavior would not have access to the raw number. 1. Let _res_ be ! FormatNumericToString(_pluralRules_, _n_).
- 1. Let _s_ be _res_.[[FormattedString]].
- 1. Let _operands_ be ! GetOperands(_s_).
- 1. Return ! PluralRuleSelect(_locale_, _type_, _n_, _operands_).
+ 1. Return ! PluralRuleSelect(_locale_, _type_, _res_.[[FormattedString]]). |
299e92c
to
a93d608
Compare
a93d608
to
b8993d2
Compare
Fixes #593