Re: Proposal for variadic functions

Michael Kay <mike@saxonica.com> writes:
> TODO: define the rules for evaluation of default values, e.g. can they
> be context dependent (if so, what is the context), can the default
> value of one argument depend on the supplied values of other
> arguments, etc.

I can see how the context would be useful, though it seems quite
complicated. Allowing one argument to depend on the supplied values of
other arguments seems odd. You mentioned Python at the beginning of your
message, does Python allow this in some form?

> For compatibility, format-date#2 and format-date#5 remain available as
> references to virtual fixed-arity functions that map directly to the
> variadic function.

How does that work? Is this a special case for backwards compatibility,
or is something else going on?

> C. Array-variadic functions.
>
> In an array-variadic function, the last parameter has an array type.
> If the last parameter is at position N, then the supplied arguments at
> position N, N+1. N+2, etc, are combined into an array, and the array
> is passed as the value of the last parameter. The caller also has the
> option of passing an actual array as the value of the argument; this
> is done by using a keyword argument. The array has an implicit default
> of [].

Just testing my understanding. Given

  function f($x as xs:integer, $y as array(xs:integer))

I could write:

  f(1) ===> f(1, array {})
  f(1, 3, 4, 5) ==> f(1, array { (3,4,5) })
  f(1, array { (3,4,5) }) ===> f(1, array { array { (3,4,5) }})
  f(1, $y=array { (3,4,5) }) ===> f(1, array { (3,4,5) })

Is that right?

> Typical example: serialize(). You can supply any keywords you like;
> the function will ignore any that it doesn't recognise.

“Will ignore” is the same as, “they will be added to the map and passed
to the function, but the function ignores map values it doesn’t
recognize”, yes?

                                        Be seeing you,
                                          norm

--
Norm Tovey-Walsh
Saxonica

Received on Tuesday, 8 December 2020 10:05:50 UTC