-
-
Notifications
You must be signed in to change notification settings - Fork 36
Define function composition for :number and :integer values #823
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
Changes from all commits
0cd061b
90ef5e3
55a6250
f924beb
484eae3
4103afa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -422,6 +422,20 @@ The following options and their values are required to be available on the funct | |||||
- `maximumSignificantDigits` | ||||||
- ([digit size option](#digit-size-options)) | ||||||
|
||||||
If the _operand_ of the _expression_ is an implementation-defined type, | ||||||
such as the _resolved value_ of an _expression_ with a `:number` or `:integer` _annotation_, | ||||||
it can include option values. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "can" reads like "MAY", but the other suggested text reads like these "MUST" exist (that is, must be permitted). Perhaps:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the thread above; the language currently covers numerical types that are not resolved values. With that context, changing this to "it includes" seems a bit wrong? |
||||||
These are included in the resolved option values of the _expression_, | ||||||
with _options_ on the _expression_ taking priority over any option values of the _operand_. | ||||||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
> For example, the _placeholder_ in this _message_: | ||||||
> ``` | ||||||
> .input {$n :number notation=scientific minimumFractionDigits=2} | ||||||
> {{{$n :number minimumFractionDigits=1}}} | ||||||
> ``` | ||||||
> would be formatted with the resolved options | ||||||
> `{ notation: 'scientific', minimumFractionDigits: '1' }`. | ||||||
|
||||||
> [!NOTE] | ||||||
> The following options and option values are being developed during the Technical Preview | ||||||
> period. | ||||||
|
@@ -489,6 +503,14 @@ MUST be multiplied by 100 for the purposes of formatting. | |||||
|
||||||
The _function_ `:number` performs selection as described in [Number Selection](#number-selection) below. | ||||||
|
||||||
#### Composition | ||||||
|
||||||
When an _operand_ or an _option_ value uses a _variable_ annotated, | ||||||
directly or indirectly, by a `:number` _annotation_, | ||||||
its _resolved value_ contains an implementation-defined numerical value | ||||||
of the _operand_ of the annotated _expression_, | ||||||
together with the resolved options' values. | ||||||
|
||||||
### The `:integer` function | ||||||
|
||||||
The function `:integer` is a selector and formatter for matching or formatting numeric | ||||||
|
@@ -498,7 +520,6 @@ values as integers. | |||||
|
||||||
The function `:integer` requires a [Number Operand](#number-operands) as its _operand_. | ||||||
|
||||||
|
||||||
#### Options | ||||||
|
||||||
Some options do not have default values defined in this specification. | ||||||
|
@@ -538,6 +559,18 @@ function `:integer`: | |||||
- `maximumSignificantDigits` | ||||||
- ([digit size option](#digit-size-options)) | ||||||
|
||||||
If the _operand_ of the _expression_ is an implementation-defined type, | ||||||
such as the _resolved value_ of an _expression_ with a `:number` or `:integer` _annotation_, | ||||||
it can include option values. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ibid. |
||||||
In general, these are included in the resolved option values of the _expression_, | ||||||
with _options_ on the _expression_ taking priority over any option values of the _operand_. | ||||||
Option values with the following names are however discarded if included in the _operand_: | ||||||
eemeli marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
- `compactDisplay` | ||||||
- `notation` | ||||||
- `minimumFractionDigits` | ||||||
- `maximumFractionDigits` | ||||||
- `minimumSignificantDigits` | ||||||
|
||||||
> [!NOTE] | ||||||
> The following options and option values are being developed during the Technical Preview | ||||||
> period. | ||||||
|
@@ -605,6 +638,14 @@ MUST be multiplied by 100 for the purposes of formatting. | |||||
|
||||||
The _function_ `:integer` performs selection as described in [Number Selection](#number-selection) below. | ||||||
|
||||||
#### Composition | ||||||
|
||||||
When an _operand_ or an _option_ value uses a _variable_ annotated, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "uses" seems wrong to me?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This language was suggested by @stasm in #814 (comment), and is currently the same across the three PRs. Would it be ok to not nitpick on this now, and iterate on the exact language once these changes have first landed? |
||||||
directly or indirectly, by a `:integer` _annotation_, | ||||||
its _resolved value_ contains the implementation-defined integer value | ||||||
of the _operand_ of the annotated _expression_, | ||||||
together with the resolved options' values. | ||||||
|
||||||
### Number Operands | ||||||
|
||||||
The _operand_ of a number function is either an implementation-defined type or | ||||||
|
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.
We are defining
:number
and:integer
here. Is "such as" needed?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 "such as" is making sure that the resolved value type is included in the "an implementation-defined type" set of possibilities.
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.
Presumably it would be that, otherwise the result would be bad operand?
Why does the operand need to be of the implementation-defined variety? Aren't option values also applicable to, for example, accepted literal values?
Why wouldn't the options "stick to" the value?
Are you trying to say that the resolved value input to the function might be influenced by ("include") the options previously applied? Should we be more direct?
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'm trying to follow our practice of not defining exactly what a "number" type is, while allowing for some implementation-defined number types, such as the resolved value coming from a
:number
annotation, to contain options within the value of the operand.So this is covering each of the following use cases:
{$x :number}
where in a JS context that could be formatted with
{ x: BigInt(42) }
, i.e. using a language-specific numerical type.{$y :number style=currency}
where in a JS context that could be formatted with
{ y: Object.assign(new Number(42), { options: { currency: 'EUR' } }) }
,i.e. an object that carries both a numerical value and a bag of options.
.local $z = {42 :number notation=compact} {{{$z :number compactDisplay=long}}}
so that in the placeholder the options of the operand
$z
can be combined with the expression options.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.
Right. We're on the same page technically. I'm bikeshedding the language.
I think the challenge for me is that "implementation-defined type" appears to exclude some values (such as literal representation). It's not clear to me if we require the implementation to resolve it to an implementation-defined type. For example, we say:
... but we don't say that the literal becomes one of the implementation-defined types (although it might).
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 thing is, though, that a literal representation of a number cannot include option values within the operand. The annotation of a literally represented number can absolutely have options, but its operand cannot.
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.
What about transitivity?
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 that example, when resolving the expression defining the value of
$b
, its operand is a resolved value, an implementation-defined type. The numerical value contained in that implementation-defined type is the number 42, and it includes a bag of resolved options{ signDisplay: 'always' }
.When resolving the value of
$b
or formatting the placeholder{$b}
, the only impact that the literal origin of the value should have is that the fallback string that's used for it is|42|
, and not e.g.$x
.