-
-
Notifications
You must be signed in to change notification settings - Fork 35
Implement :unit as Proposed RECOMMENDED in the registry
#922
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 14 commits
f05d0ba
9a5b46a
4a623f9
aaba292
8786990
b5ef049
59ae657
8d83a8f
a76eedc
d0eb3e3
57582ee
0ce878b
8fe64c9
0c7beb2
b90a720
13e33f0
b5cf412
94c0dec
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -559,6 +559,175 @@ together with the resolved options' values. | |||||||||||
|
|
||||||||||||
| The _function_ `:currency` performs selection as described in [Number Selection](#number-selection) below. | ||||||||||||
|
|
||||||||||||
| ### The `:unit` function | ||||||||||||
|
|
||||||||||||
| The _function_ `:unit` is a selector and formatter for unitized values, | ||||||||||||
| that is, numeric values associated with a unit of measurement. | ||||||||||||
| This is a specialized form of numeric selection and formatting. | ||||||||||||
|
|
||||||||||||
| > [!IMPORTANT] | ||||||||||||
| > Implementation of this function is **_OPTIONAL_**. | ||||||||||||
| > Any implementation of this function is strongly encouraged to follow this specification. | ||||||||||||
|
|
||||||||||||
| #### Operands | ||||||||||||
|
|
||||||||||||
| The _operand_ of the `:unit` function can be one of any number of | ||||||||||||
| implementation-defined types, | ||||||||||||
| each of which contains a numerical `value` plus a `unit` | ||||||||||||
| or it can be a [Number Operand](#number-operands), as long as the _option_ | ||||||||||||
| `unit` is provided. | ||||||||||||
| The _option_ `unit` MAY be used to override the units of an implementation-defined type, | ||||||||||||
| provided the units are compatible and the implementation supports conversion. | ||||||||||||
|
||||||||||||
| The _option_ `unit` MAY be used to override the units of an implementation-defined type, | |
| provided the units are compatible and the implementation supports conversion. | |
| The _option_ `unit` MAY be used to override the unit value of an implementation-defined type, | |
| if the implementation supports unit conversion. | |
| However, if the units cannot be converted, then the unit value is not overridden and a Bad Option error must be emitted. |
Side issue
Frankly, currency is even worse. Suppose we have input of a implementation-defined parameter $n = {value=300, currency=EUR} and we format or select {$n :currency currency=JPY}. That is really nasty, displaying 300¥. However, there is no stable conversion possible.
So for :currency, we should make it really clear that if there is an implementation-defined operand that contains a currency value, the currency option is invalid, no matter its value.
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.
Currency explicitly says that this is an error.
The unit example is a leftover from early on. I will make it use usage. We should do the same thing with the unit option that we do with the currency option: you can use it to create a unit value with a number operand. Otherwise it is an error.
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.
Sounds great.
macchiati marked this conversation as resolved.
Show resolved
Hide resolved
macchiati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
macchiati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
aphillips marked this conversation as resolved.
Show resolved
Hide resolved
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.
It's not clear here that not all "implementation-defined types" are necessarily supported as 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.
I'm not sure I understand. I don't think this needs to indicate that some types are not supported as operands.
This text is not about the operand. It's about the handling of option values within a resolved value. It is nearly boilerplate, since most of our functions have a variation of this sentence. In practice, it might be better to say something like the following, which doesn't care what the operand is or is not:
| If the _operand_ of the _expression_ is an implementation-defined type, | |
| such as the _resolved value_ of an _expression_ with a `:unit` _annotation_, | |
| it can include _option_ values. | |
| The _resolved value_ of an _expression_ with a `:unit` _annotation_ | |
| includes the result of _option resolution_. |
Such a boilerplate would be altered if some of the options were required to be filtered by the function. unit is candidate for this in :unit (since the unit presumably is now part of the resolved operand).
Uh oh!
There was an error while loading. Please reload this page.