-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Filtering by type in lookup expressions #1456
Comments
For named types would we use a construct |
I'm working backwards from the common case of selection using a record type to the more general case (just as path expressions focus on having convenient syntax for the common cases). But I think we could achieve something like
but allowing the |
Let’s assume we have XML encoded either in a document or in a “structured item” (which is how we occasionally call maps/arrays internally). Are the following two expressions comparable to some extent / would they both return the element let $doc := document { <a/> }
return $doc / element() let $struct := [ <a/> ]
return $struct ?~ element() If we wanted to try to make the syntax accessible to non-experts, would it be fair to present |
It would be great if we could agree on a collective term for "maps and arrays". "Structured item" feels too generic to me. I've toyed with terms like "tabulation", "tabula", "composition", "dataset", "compendium", "aggregate". Perhaps "combo"? It's best to have a word that stands out from the crowd if we can't find one whose meaning is self-explanatory. With "/", the RHS is always selecting nodes, and we are primarily selecting nodes by nodekind and name, occasionally by type. So we can write The syntax |
Is there any restriction on using something like |
There's no restriction on using bare NCNames as atomic type names or declared item type names. It's quite legal today to do |
My first reaction is to use syntax like:
or
or
or
Or why not:
I am against introducing new, unreadable symbols in the already quite messed symbol-set we are using at present. Readability must have much higher priority in our design than introducing new, fancy (cryptic) symbols. |
And of course, if the proposal for Total Maps is accepted, Then any constant non-map value can be represented-as / coerced-to a map: map {
'\' : ()
} (: produces the empty sequence for any lookup:) |
We definitely need a convenient way to do the equivalent of We can't use that syntax because I've toyed with all sorts of alternatives and listened to suggestions, and I can't come up with anything better than ~type. So I'm going to raise a PR to that effect. I'm also inclined to reinforce the association of
and but perhaps that should be a separate proposal. |
My preference is very much more for: |
We have dropped the syntax
??type(T)
for filtering the results of lookup expressions, because of problems with syntax ambiguity. This issue seeks an alternative.Although selection by type also makes sense with shallow lookup, it is most relevant with deep lookup. The main need arises with intermediate steps of a path such as
?? X ?? Y
which gives a dynamic error if X selects something that is not a map or array. This is consistent at one level with// X // Y
, except that// X
can never select something that isn't a node.The main problems with filtering using an
[. instance of record(p, q)]
predicate is that it's very long-winded. For example, if we want to select only those members of a selected array that are sequences of a particular record type, without flattening everything else, we have to write something like?? values::* ?[. instance of record(p, q)+] ? *
, which is a bit of a nightmare.Starting from the end goal, I would like to be able to write something close to
??record(first, last)
to select all the items of this record type at any depth. We know that syntax doesn't work, because??NCName
is already taken. That's also true for??items::record(first, last)
, unless we change the rules for what can appear after::
.Also, there's another syntax hazard: what we want here is a SequenceType, not an ItemType, and that means that it can contain a trailing
?
occurrence indicator, which is easily confused with the next lookup operator in a path.Looking at it from all angles, I do feel the best solution is to prefix the
record(first, last)
with a marker character so that we know we've got a type filter here. Characters that might do the job include@
,#
,$
,%
,^
,~
. Of these, my preference remains~
, for three reasons:(a) it's currently unused: overloading a different symbol is more likely to cause visual confusion
(b) one of the traditional uses of
~
is to indicate a "matches" or "is kind of like" relationship.(c) there's a mnemonic association between "tilde" and "type" (compare "at" and "attribute")
The text was updated successfully, but these errors were encountered: