Re: Keyword arguments [was fn:slice]

On Sat, Dec 5, 2020 at 3:18 PM Michael Kay <mike@saxonica.com> wrote:

>
>
> On 5 Dec 2020, at 21:01, Dimitre Novatchev <dnovatchev@gmail.com> wrote:
>
> What about something as simple as this:
>
> myFunction($arg1 as item()*, $arg2 as xs:integer default: 15, $arg3 as
> xs:string default: "Hi")
>
>
> On the declaration side, this is very similar to what I've been proposing
> for XSLT - see
> https://qt4cg.org/branch/master/xslt-40/Overview-diff.html#xsl-function-name
>
> The difference is that I proposed this would actually declare three
> functions myFunction#1, myFunction#2, and myFunction#3, because it can be
> called with 1, 2, or 3 arguments, and because its existence rules out the
> existence of any other function with this name and arity 2, 3, or 4.
>

Actually not!

  myFunction(/*/name)

is not the same as

   myFunction#1(/*/name)

  actually

  myFunction(/*/name)

is the same as

    myFunction#3(?, 15, "Hi")(/*/name)


and this is different from

   myFunction#1(/*/name)

So, we can define a one-argument function overload and call it explicitly
as:

    myFunction#1(/*/name)

and / or have the different call:

   myFunction#3(?, 15, "Hi")(/*/name)

or, this can be  abbreviated:

     myFunction#3(?)(/*/name)

Thanks,
Dimitre

And I was thinking it purely as a better way of declaring a family of
> functions, not as something linked to changes in function call syntax.
>
>
> "*You can also use named arguments instead of positional arguments when
> invoking a method. When using named arguments, you specify the parameter
> name followed by a colon (":") and the argument. Arguments to the method
> can appear in any order, as long as all required arguments are present. *"
>
>
> The main challenge is defining rules for unambiguously binding a function
> call to a declared function when there are several declared functions with
> the same name. This needs to handle both binding of static function calls
> and dynamic references.
>
> Another detail, particularly for XSLT, is defining the rules for
> overriding of functions in other packages.
>
> Michael Kay
> Saxonica
>
>

Received on Saturday, 5 December 2020 23:58:45 UTC