Giter Site home page Giter Site logo

Comments (9)

dnovatchev avatar dnovatchev commented on July 18, 2024

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.

michaelhkay avatar michaelhkay commented on July 18, 2024

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.

ChristianGruen avatar ChristianGruen commented on July 18, 2024

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.

Arithmeticus avatar Arithmeticus commented on July 18, 2024

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.

michaelhkay avatar michaelhkay commented on July 18, 2024

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.

ChristianGruen avatar ChristianGruen commented on July 18, 2024

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.

Arithmeticus avatar Arithmeticus commented on July 18, 2024

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.

ChristianGruen avatar ChristianGruen commented on July 18, 2024

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.

michaelhkay avatar michaelhkay commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.