Comments (15)
The proposal seems fine. I only wonder why the example uses name[contains(string(), $key)]
instead of simply name[contains(., $key)]
. Just curious.
from qtspecs.
…just an arbitrary example, data()
, text()
, etc. would work as well (personally, I tend to use text()
if I know that a single text node is to be addressed).
from qtspecs.
This is really nice!
With this proposal implemented, then ?
becomes the function-composition operator:
$f ? (1, 2, 3)
is $f(1), $f(2), $f(3)
Then:
$g ? $f ? (1, 2, 3)
is $g ? ($f(1), $f(2), $f(3))
is $g($f(1)), $g($f(2)), $g($f(3))
Thus:
$g ? $f
is exactly the function composition of $f
and $g
.
We might need to specify that ?
is right-associative.
Good result!
from qtspecs.
I think the "?" operator as currently defined on maps and arrays is left-associative.
let $a := [map{'k':[1,2]}, map{'k':[3,4]}]
return $a ? k ? 2
only works if you interpret it as ($a ? k) ? 2
; the reading $a ? (k ? 2)
makes no sense.
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:
If the KeySpecifier is a ParenthesizedExpr, then the expression E?(S) is equivalent to
for $e in E, $s in fn:data(S) return $e($s)
which would work whenever $e is an arity-one function that accepts a single atomic value as an argument.
from qtspecs.
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:
If the KeySpecifier is a ParenthesizedExpr, then the expression E?(S) is equivalent to
for $e in E, $s in fn:data(S) return $e($s)
which would work whenever $e is an arity-one function that accepts a single atomic value as an argument.
-
Which "current spec" are you referring to:
4.0
or3.1
? -
Does this mean that
$f?($x)
is valid but not$f?$x
?
from qtspecs.
I was referring to the 3.1 spec, but the current 4.0 draft also has this text.
Yes, in 3.1 $f?$x
is a syntax error. In 4.0 the grammar allows it, but the semantics proposed in §4.14.3.2 don't seem right.
from qtspecs.
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.
from qtspecs.
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:
If the KeySpecifier is a ParenthesizedExpr, then the expression E?(S) is equivalent to
for $e in E, $s in fn:data(S) return $e($s)
which would work whenever $e is an arity-one function that accepts a single atomic value as an argument.
- Which "current spec" are you referring to:
4.0
or3.1
?- Does this mean that
$f?($x)
is valid but not$f?$x
?
I was referring to the 3.1 spec, but the current 4.0 draft also has this text.
Yes, in 3.1
$f?$x
is a syntax error. In 4.0 the grammar allows it, but the semantics proposed in §4.14.3.2 don't seem right.
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?:
from qtspecs.
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.
from qtspecs.
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 ? 😄
from qtspecs.
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 3
)
from qtspecs.
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.
from qtspecs.
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.
from qtspecs.
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 ??
will lead to new questions that are difficult to answer.
If no one objects, I would tend to close this proposal.
from qtspecs.
The CG agreed to close this issue without action meeting 59.
from qtspecs.
Related Issues (20)
- new function - fn:tail-recurse a function to allow users to hand roll their recursion and guarentee tail recursion. HOT 11
- Attribute priority for xsl:accumulator-rule HOT 1
- Generalization of Deep Updates HOT 2
- Rendition of RFC2119 terms HOT 1
- Seralization Parameters: Indentation, Whitespace, Newlines HOT 2
- Function Identity: Treating function items with identical bodies HOT 12
- QT4CG-078-01 fn:unparsed-text-lines, normalize newlines HOT 4
- XSLT on-no-match="shallow-copy-all" - revised rules HOT 3
- XSLT xsl:next-match with select attribute HOT 1
- $sequence-of-maps ? info() HOT 4
- Node constructor vs. otherwise/map constructor HOT 3
- XSLT: system-property('xsl:xpath-version')
- fn:format-dateTime: Properties
- fn:json-to-xml: `number-parser` option HOT 1
- `??type(T)` in lookup expressions - shortcuts
- for member allowing empty HOT 2
- Allow sequence constructor in extension instructions that are implemented with named templates HOT 1
- Add a new function `fn:html-doc` HOT 2
- XSLT: add xsl:switch to list of instructions within which whitespace is ignored
- Add decimal-divide function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qtspecs.