Skip to content
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

Clarify the formatting spec wrt. inspecting formattable values #515

Closed
stasm opened this issue Nov 6, 2023 · 9 comments
Closed

Clarify the formatting spec wrt. inspecting formattable values #515

stasm opened this issue Nov 6, 2023 · 9 comments
Labels
formatting LDML46.1 MF2.0 Draft Candidate resolve-candidate This issue appears to have been answered or resolved, and may be closed soon.

Comments

@stasm
Copy link
Collaborator

stasm commented Nov 6, 2023

Originally posted by @stasm in #511 (comment)

I'm not sure if the spec is currently clear enough about the requirement to allow functions to inspect the raw value and the formatting options of their arguments. Specifically, while a function may eagerly format its operand to a string, it should (must?) also return the raw underlying value and the formatting options used for formatting, in case another function wants to extend them or use them for other logic. Consider:

local $a = {1 :number minIntegerDigits=3} // formats as 001.
local $b = {$a :number minFractionDigits=3} // formats as 001.000
// min integer digits are preserved from the previous call.
input {$item :noun case=accusative count=1}
local $colorMatchingGrammaticalNumberGenderCase = {$color :adjective accord=$item}
// :adjective inspects $item to learn about case=accusative, count=1
@stasm
Copy link
Collaborator Author

stasm commented Nov 6, 2023

Originally posted by @aphillips in #511 (comment)

I think it has to work that way. I don't think "eager" evaluation is necessarily to a string. It is to a "formattable". Otherwise format-to-parts wouldn't work nor would (as you point out) later annotation. Also, selectors wouldn't work:

input {$num :number maxFactionDigits=0}
match {$num}
when one {{ won't get here because {$num} won't be the string 'one' }}
when * {{  :-( }}

What "eager" evaluations might do is copy the value and modify the copy:

input {$startDate :systemTime}
local $endDate = {$startDate :add unit=days increment=6}

@eemeli
Copy link
Collaborator

eemeli commented Nov 7, 2023

Here's the full set of methods/accessors that the proposed JS implementation uses:

  • get options
  • get value
  • format to string
  • format to parts
  • select keys

As far as I can tell, that's the minimal set covering all the possibilities.

If it's not clear that the spec effectively leads to that sort of an implementation, that might indeed be good to clarify in its text.

@catamorphism
Copy link
Collaborator

Originally posted by @stasm in #511 (comment)

I'm not sure if the spec is currently clear enough about the requirement to allow functions to inspect the raw value and the formatting options of their arguments. Specifically, while a function may eagerly format its operand to a string, it should (must?) also return the raw underlying value and the formatting options used for formatting, in case another function wants to extend them or use them for other logic. Consider:

Is it that the function has to return that, or that the formatter implementation has to bind the name $a to a value such that the raw value and options can be inspected? Requiring implementors of custom functions to write their functions this way seems challenging.

By the way, this seems like a case for making the spec be less abstract about what a "resolved value" is allowed to be.

@eemeli
Copy link
Collaborator

eemeli commented Nov 8, 2023

Specifically, while a function may eagerly format its operand to a string, it should (must?) also return the raw underlying value and the formatting options used for formatting, in case another function wants to extend them or use them for other logic. Consider:

local $a = {1 :number minIntegerDigits=3} // formats as 001.
local $b = {$a :number minFractionDigits=3} // formats as 001.000
// min integer digits are preserved from the previous call.

One thing to note here is that the "raw underlying value" should in this case be the number 1 for both $a and $b, rather than the source string '1'. So perhaps we should not use the term "raw" here.

@aphillips
Copy link
Member

I think this needs concrete suggestions in order to be actionable. Can we produce a PR with proposed changes?

@aphillips aphillips added LDML45 LDML45 Release (Tech Preview) resolve-candidate This issue appears to have been answered or resolved, and may be closed soon. labels Jan 8, 2024
@catamorphism
Copy link
Collaborator

I'm working on a proposal for this.

catamorphism added a commit to catamorphism/message-format-wg that referenced this issue Feb 6, 2024
This commit also includes the changes to the spec
implied by this design doc, but will be split up into
separate commits before submitting a PR.
catamorphism added a commit to catamorphism/message-format-wg that referenced this issue Feb 6, 2024
catamorphism added a commit to catamorphism/message-format-wg that referenced this issue Feb 13, 2024
This commit also includes the changes to the spec
implied by this design doc, but will be split up into
separate commits before submitting a PR.
catamorphism added a commit to catamorphism/message-format-wg that referenced this issue Feb 13, 2024
catamorphism added a commit to catamorphism/message-format-wg that referenced this issue Feb 14, 2024
This proposed design doc addresses an issue titled
"inspecting formattable values", which is really about dataflow
through the formatter and structuring it to make function calls
compose with each other.
catamorphism added a commit to catamorphism/message-format-wg that referenced this issue Feb 14, 2024
This proposed design doc addresses an issue titled
"inspecting formattable values", which is really about dataflow
through the formatter and structuring it to make function calls
compose with each other.
@aphillips aphillips added LDML46 LDML46 Release (Tech Preview - October 2024) and removed resolve-candidate This issue appears to have been answered or resolved, and may be closed soon. LDML45 LDML45 Release (Tech Preview) labels Feb 18, 2024
@aphillips
Copy link
Member

Moving to LDML46 to match Tim's proposal.

aphillips pushed a commit that referenced this issue May 20, 2024
* Add design doc for dataflow for composability (#515)

This proposed design doc addresses an issue titled
"inspecting formattable values", which is really about dataflow
through the formatter and structuring it to make function calls
compose with each other.

* Add pull request link

* Add link to spec PR

* Add correct image for second diagram

* Add one more alternative

* Add another alternative
@aphillips aphillips added LDML46.1 MF2.0 Draft Candidate and removed LDML46 LDML46 Release (Tech Preview - October 2024) labels Sep 16, 2024
@catamorphism
Copy link
Collaborator

Does #728 address this fully? (I think it does.)

@eemeli eemeli added the resolve-candidate This issue appears to have been answered or resolved, and may be closed soon. label Oct 12, 2024
@aphillips
Copy link
Member

Hi @stasm. I know you've been busy. Are you satisfied with this issue's resolution? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting LDML46.1 MF2.0 Draft Candidate resolve-candidate This issue appears to have been answered or resolved, and may be closed soon.
Projects
None yet
Development

No branches or pull requests

4 participants