-
Notifications
You must be signed in to change notification settings - Fork 17
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
Generalize lookup operator for function items #51
Comments
The proposal seems fine. I only wonder why the example uses |
…just an arbitrary example, |
This is really nice! With this proposal implemented, then
Then:
Thus:
We might need to specify that Good result! |
I think the "?" operator as currently defined on maps and arrays is left-associative.
only works if you interpret it as Nevertheless, I think the interpretation of '?' as a mapped function call makes some sense. One concern is that the '?' operator (in its general form, with a parenthesised expression on the RHS) atomizes the result of the RHS expression. That makes sense for array and map lookup, but it doesn't obviously make sense for function application. Interestingly, I don't think it was ever the intention, but the current spec doesn't actually say explicitly that when used in the form $a?(expression), every item in $a must be a map or an array. Rather it says:
which would work whenever $e is an arity-one function that accepts a single atomic value as an argument. |
|
I was referring to the 3.1 spec, but the current 4.0 draft also has this text. Yes, in 3.1 |
It would certainly be possible (though clumsy) to change the rule so that atomization of the RHS only happens if the function signature requires an atomic value (which is true, of course, for maps and arrays). But it might be simpler and less error-prone if we allow the lookup operator only when the LHS is a function whose signature requires the (single) argument to be a singleton or optional atomic value. |
Quite interestingly, both BaseX 10.4 and Saxon 11.4 do not implement the current (3.1) rules, or is there something I am not understanding correctly?: |
The implementors of both Saxon and BaseX presumably read the section heading "The lookup operator for maps and arrays" which is all about maps and arrays, and failed to notice that for one particular case of the syntax, the rule that the LHS must be a map or array has been accidentally omitted. |
Shall we issue bugs then ? 😄 |
Also, a test must be added to the test suite asserting that the expressions in the screenshots are evaluated successfully (and the result of the evaluation is |
I've added an issue against the 3.1 specs at w3c/qtspecs#46. I think the intent is perfectly clear that the lookup operator is only designed to apply to maps and arrays, but there is a rule missing from the spec. |
I agree that we should maintain the atomization of the RHS result, and not make the behavior dependent on the type of the LHS expression. |
I would still be in favor of generalizing lookups to arbitrary functions – we had a use case for that in the past. I have concerns, however, that the introduction of the deep lookup operator If no one objects, I would tend to close this proposal. |
The CG agreed to close this issue without action meeting 59. |
The current lookup operator is a specialized expression for maps and arrays. All kinds of data structures can be realized with functions, and maps and arrays are functions as well, so it would be pretty straightforward to extend the lookup operator to arbitrary function items:
Use Cases
Return name elements whose string values contain supplied substrings
Return squares of supplied integers
Remarks
XPTY0004
must be raised if the wildcard*
is specified as key, and if the input is neither a map nor an array.The text was updated successfully, but these errors were encountered: