-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
[FEEDBACK] The re-use of :function
between "annotation" and "output" positions can be a bit confusing
#818
Comments
Thanks for the feedback. I commented in #819 about why The spec tries to make clear that functions can be formatting, selection... or some functions can do both formatting and selection. The ability to do both is intentional and important: you want the selector to be selecting the same way that the formatter is formatting. Important: this is partially false:
Matching (selectors) filter and stack rank the list of patterns (variants). Currently none of the date/time functions perform selection, so you should focus on string or number functions for examples. These functions describe the interaction of formatting and selection options. An example of this would be in the
Notice that the selector does not use the formatted string for matching values. It uses the resolved value of This message is interesting because the keys Some formatting options ( |
Firstly, I realize my original message had some errors, sorry for the confusing examples. Thanks for the explanation on formatting vs selection, and the stack ranking behaviour of selection. The behaviour here is now more clear to me. I still however find the syntax to be rather self-inconsistent. Namely the fact that expressions in
Here, the However, the I find not the individual behaviours here confusing - they both make sense. What I find confusing is the syntax of Or alternately:
Here This syntax could even be simplified allowing one to emit the
I think the above case would make implementations marginally more complex. But because rebinding is still disallowed, and shadowing is already possible, I don't think it's incredibly complex. To reiterate my concern one more time: I find it highly confusing that the variable name in the variable expression is both a variable name that is bound to to create a shadowed variable binding in the context of the message, and a variable that refers to data from the input. This is especially the case because an identical expression in a |
@lucacasonato Thanks. The WG is discussing this very problem in e.g. #824 and the associated (unresolved) design document selection-declaration. |
We went with Option F in the balloting for selection-declaration, so |
I think in the interim we have addresses this with the resolved value work, so marking as a potential r-c. |
During the last call I gave some feedback that I found it confusing that
:function
s are used in two (or maybe three) somewhat distinct ways, without any obvious syntax difference. @stasm asked me to open an issue.Render functions / formatting functions
Inside of a placeholder expression in a simple message or quoted pattern, and also in the expression in a local declaration, the function acts as a rendering function, that determines how a value is formatted into the output. In code, this would be equivalent to:
As far as I understand, the
formatted_value
could be a string, but it could also a more complex value that the renderer then will render in some way - like callingtoString()
on it in JS for example.So really it'd be more something like
I think this mostly makes sense and is relatively clear. (I do find it confusing that this essentially allows you to use annotation expressions in a way that is more or less identical to markup, by having the renderer special case some shapes of
formatted_value
, but I digress.)Match selectors
Match selectors also look like placeholder expressions. Here however my first intuition tells me that the function is effectively being called with two arguments: the value, and an expected value (the key in the variant). It also does not return a string or more complex value for the renderer, but it returns a boolean.
After thinking about it some more, I think what it is really trying to model is:
I think that makes much more sense - but this is not explained at all anywhere. If this is the mental model that we think developers should have, we should try to make that clearer.
This mental model is however undermined by the fact that annotations are required in expressions in selectors. If they were not (which I am not advocating for, because it would probably lead to worse tooling), the second mental model would work quite well - it could be simply explained.
What is also very unclear to me, is what it means to have formatting options on functions annotations in expressions in selectors. What does it mean to match on a
:datetime style=short
, are we matching on the underlying string value, or on the object representing date-time?Input declarations
Input declarations also use the same placeholder expression syntax. Here however, the syntax initially looks like
:function
is a pure type annotation on the input variable. So in pseudocode:This however is not at all how this behaves. The input declaration behaves much more like a local declaration that assigns the same variable as it operates on:
I think that expressing this as
.local $value = {$value :function}
is actually much clearer. This is not valid syntax right now however.EDIT: @aphillips corrected me - my understanding here was wrong. Indeed this does really behave just like a type annotation, which I find makes it even more confusing. For example, this is allowed right now:But it does not actually format anything in percent style.I would find the syntax less confusing if the behaviour were identical to this imaginary local declaration:Alternatively, a different syntax for type annotations would also work to disambiguate this from the other annotation expression things.EDIT 2: I had misunderstood. My original understanding was correct
The text was updated successfully, but these errors were encountered: