- From: Tom Hillman <tom@expertml.com>
- Date: Wed, 2 Dec 2020 11:27:11 +0000
- To: Michael Kay <mike@saxonica.com>
- Cc: Dimitre Novatchev <dnovatchev@gmail.com>, Dave Pawson <dave.pawson@gmail.com>, "Liam R. E. Quin" <liam@fromoldbooks.org>, public-xslt-40@w3.org
- Message-ID: <d59411d8-4583-4672-92b3-cfcc5469f541@Spark>
> serialize($x, method: 'json', indent: true())
>
> Specifically, any keyword: value pairs in the function call are gathered together into a map, which is supplied as the last argument of the call, and the above call is treated as a call on the arity=2 function because there are one-or-more keyword:value arguments supplied.
I would suggest that they are explicitly the trailing parameters in the function call unless we want to include things like map{'method': 'json'} => serialize($x, indent: true())
But yes, that's a wonderful idea. Should there also be some syntactic sugar on the function definition end, allowing for default options?
<xsl:function name="my:serialize">
<xsl:param name="node" as node()/><!-- usual parameter -->
<xsl:option name="method" select="'adaptive'"/><!-- option supplied as a map, with a default -->
<!-- rest of function -->
</xsl:function>
T
_________________
Tomos Hillman
eXpertML Ltd
+44 7793 242058
On 2 Dec 2020, 10:58 +0000, Michael Kay <mike@saxonica.com>, wrote:
>
>
> > On 2 Dec 2020, at 09:58, Tom Hillman <tom@expertml.com> wrote:
> >
> > I see more and more functions taking an options map as the final argument...
> >
>
> And perhaps that could be formalised into the language syntax so instead of
>
> serialize($x, map{'method':'json', 'indent':true()})
>
> you can write
>
> serialize($x, method: 'json', indent: true())
>
> Specifically, any keyword: value pairs in the function call are gathered together into a map, which is supplied as the last argument of the call, and the above call is treated as a call on the arity=2 function because there are one-or-more keyword:value arguments supplied.
>
> I write calls like that a lot in xsl:message for debugging, and simplifying the syntax would be a very useful convenience.
>
> If the function signature declares the options parameter as a record type rather than a general map type then it also gives you the opportunity for static checking that the option names are right.
>
> Michael Kay
> Saxonica
>
Received on Wednesday, 2 December 2020 11:33:20 UTC