Comments (9)
I strongly support this suggestion.
So far providing options in a map seemed completely confusing to me - how would the customer know what keys / entries any such map might have (added or removed) and how to maintain consistency between different implementations...
Having such options represented as a record answers at least 50% of these concerns.
Thank you!
from qtspecs.
Now that we've introduced constructor functions for record types, the names of the record types (and perhaps the order of fields) becomes rather more important. For example, people would be able to write
serialize($input, opt:serialization-params(method:="xml"))
in preference to writing
serialize($input, map{"method":"xml"})
But since the record type names are global, this doesn't feel much like an improvement.
So we need to think about this in conjunction with issue #162. We get a real usability improvement if we allow:
serialize($input, method:="xml")
But of course that's not easy or we would have done it by now: the main obstacle is that we use the number of supplied arguments as part of the algorithm for deciding which function is being called.
One option would be to use a syntactic marker for these "pseudo-arguments":
serialize($input, %method:="xml")
from qtspecs.
One option would be to use a syntactic marker for these "pseudo-arguments":
serialize($input, %method:="xml")
As %
ressembles the annotation syntax, we could simulate the map syntax:
(: old :)
serialize($input, map{"method":"xml"})
local:whatever($data, map { '': 'empty', 'hi there': 'phrase' })
(: new :)
serialize($input, 'method':'xml')
local:whatever($data, '': 'empty', 'hi there': 'phrase')
Another challenge could be how to treat (used-defined, or possible future built-in) functions with multiple option parameters.
from qtspecs.
Since we're daydreaming about an easier syntax, what about serialize($input, (.method = "xml", .indent = true()))
. Takes advantage of familiar dot notation for properties, which is exactly what the user is fiddling with. I left off the colon in hopes that the walrus sign could be swapped for simple equality.
from qtspecs.
serialize($input, (.method = "xml", .indent = true()))
I like it, and I think the grammar works. But it's very confusing for users to know when to use =
, when to use :=
, and when to use :
.
I wonder if we could make this a proper expression usable in contexts other than function calls? That is,
(.method = "xml", .indent = true())
can be used anywhere you could write
map{"method": "xml", "indent":true()}
from qtspecs.
serialize($input, (.method = "xml", .indent = true()))
While I’m not particularly fond of the walrus syntax, it feels confusing to me to use =
, which is used for comparisons. We already use :
for map options and we use :=
for assignments, so I would prefer to stick with one of those variants.
from qtspecs.
walrus makes sense for binding -- sorry to detract from the main thing, which was suggesting dot syntax.
I wonder if initial-dot syntax could be leveraged other places to populate, query, and filter maps, records, or arrays.
from qtspecs.
walrus makes sense for binding -- sorry to detract from the main thing, which was suggesting dot syntax.
I like the dot syntax, too… preferrably without additional parentheses.
Instead of introducing more potentially idiosyncratic syntactical sugar, a bolder step could be (if it’s not too late) to question the map
keyword: Now that JSON is all around, and now that maps can also be “records”, wouldn’t it be nice if you could simply do this?
serialize($input, { "method": "html" })
let $input := <html/>
let $options := { "method": "html" }
return serialize($input, $options)
from qtspecs.
Yes, my thinking too. We reserved the bare-brace syntax for use with scripting extensions, but I can't see us wanting to go in that direction, and using it for maps makes sense now, I think.
from qtspecs.
Related Issues (20)
- parse-json: liberal parsing HOT 2
- fn:json-to-xml: 'number-parser' option HOT 2
- Backwards incompatibility caused by use of EBV in callback functions HOT 4
- Allow dynamic collations in XQuery "order by" and "group by" HOT 11
- CSV parsing - "blank" rows HOT 3
- CSV row delimiter - allowed values HOT 5
- Functions to manage namespace usage HOT 2
- Incorrect note for `fn:some` and `fn:every` HOT 5
- fn:format-number: relax restrictions on exponent-separator (possibly minus-sign, percent, per-mille) HOT 13
- Potential (low-risk) Ambiguities in XPath EBNF
- parse-csv() - simplify output HOT 1
- Spec fn:message #id using old name fn:log
- simplifying the language - attempt 2 HOT 22
- Simplifying match templates HOT 11
- Formatting XPath/XQuery HOT 2
- discussion - language pragmas HOT 6
- deep-equal() - option to compare functions liberally HOT 25
- fn:format-number: further notes
- fn:deep-equal: significant children HOT 2
- fn:ucd HOT 25
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.