- From: Reece Dunn <msclrhd@googlemail.com>
- Date: Sat, 5 Dec 2020 09:11:19 +0000
- To: Christian Grün <cg@basex.org>
- Cc: "Liam R. E. Quin" <liam@fromoldbooks.org>, Dimitre Novatchev <dnovatchev@gmail.com>, Michael Kay <mike@saxonica.com>, public-xslt-40@w3.org
- Message-ID: <CAGdtn24NmpoHxpSH3PshNy1bqdqR2Q6ANMRfv5JBBKaqhD16Kg@mail.gmail.com>
On Sat, 5 Dec 2020 at 08:50, Christian Grün <cg@basex.org> wrote: > I also believe more and more that Liam’s proposal would be both more > intuitive and more in alignment with the concept of keyword parameters > in other languages. In this example… > > declare function do-something( > $data as map(*) > ) external; > > declare function do-something( > $data as map(*), > $options as map(*) > ) external; > > do-something(data := ..., options := ...) > > …one would clearly expect the second function to be called. If keyword > arguments were equivalent to a single map argument, the code would be > legal as well, and the first function would be called. This may look > like an edge case, but maps as arguments are pretty common nowadays. > > Things might be safer if we had a dedicated options type: > > declare function do-something( > $data as map(*), > $options as options(*) > ) external; > > In that case, the example above would be rejected. > > If we stick with the current proposal for keyword arguments, maybe we > should give them another name than in Python? Maybe "option arguments" > instead? Or do we have other uses cases, apart from supplying options > with less characters? > If we have something like: $options as variadic map(*) (: allow any keyword arguments, optionally restricted by type :) $options as variadic record(a: xs:int, b: xs:string) (: allow only the specified keyword arguments :) $options as variadic some-options-type (: where some-options-type is a named alias :) that would make it possible to support variadic array arguments like my original variadic arguments proposal syntax in xpath-ng: $values as variadic array(xs:string) It could also support sequences for variadic arguments: $values as variadic xs:string* $values as variadic xs:string+ That way, it is consistent across the 3 types (sequences, maps, and arrays), and supports both keyword and variadic arguments in a single syntax. Reece > ____________________________________ > > On Sat, Dec 5, 2020 at 1:31 AM Liam R. E. Quin <liam@fromoldbooks.org> > wrote: > > > > On Fri, 2020-12-04 at 15:23 -0800, Dimitre Novatchev wrote: > > > So, one will call the function with any map as parameter and this > > > would be statically OK? > > > > Rght now that's more or less what one does with fn:transform. It's a > > bit of an unfortunate example. Yes, you call it with a map. > > > > So Mike's example is exactly what i was suggesting before in this > > regard, except i want the keywords to map to named arguments so there > > can be useful static type checking. We would need to allow optional > > arguments for transform() at least, though, and refer to it e.g. as > > fn:transform#* > > > > Then i could call > > fn:transform( > > source-node: /, > > stylesheet-location: "remove-namespaces.xsl" > > ) > > and have it behave as if it were defined as > > <xsl:function name="fn:transform"> > > <xsl:param name="source-node" as="node()" optional="yes" /> > > <xsl:param name="stylesheet-location" as="xs:anyIRI" optional="yes" > > /> > > <xsl:param name="stylesheet-node" as="node()" optional="yes" /> > > > > (or they could have select attributes, as with templates, to indicate > > optionality). > > > > Any function could then *either* be called in its positional form, *or* > > with its keyword form; since the same function is called, the arity is > > the same, and you have to supply all the required (non-optional) > > parameters. > > > > Mike i think is proposing something slightly different: that keyword > > parameters get put into a map that must then be the only argument of > > the function: fn:transform#1 takes a map as input today, and he says > > it'd be unchanged. I'd rather see the one or two unusual functions > > changed and be able to use keyword parameters everywhere. > > > > Liam > > > > > > > > > > -- > > Liam Quin, https://www.delightfulcomputing.com/ > > Available for XML/Document/Information Architecture/XSLT/ > > XSL/XQuery/Web/Text Processing/A11Y training, work & consulting. > > Barefoot Web-slave, antique illustrations: http://www.fromoldbooks.org > > > > > >
Received on Saturday, 5 December 2020 09:11:42 UTC