Re: fn:slice()

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?
____________________________________

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 08:50:05 UTC