Re: Function annotations

MarkLogic currently supports two functions for annotation and function 
discovery:

xdmp:annotation($f as function(*), $name as xs:QName) as item()*
   (: Returns only the first of multiple annotations with the same name :)

xdmp:functions() as function(*)*
   (: Returns every function in the system (built in functions and all 
functions imported) :)

The second function is necessary if you actually want to do something 
interesting with annotation discovery, although is a little inefficient. 
I've often wondered about adding an alternative that fetches functions 
based on the presence of an annotation.

John

On 12/10/16 11:38, Michael Kay wrote:
> The function annotations used by restxq, which is probably the most ambirious attempt to date to exploit function annotations, seems to rely on multiple annotations with the same name being allowed:
>
> http://exquery.github.io/exquery/exquery-restxq-specification/restxq-1.0-specification.html
>
> It uses annotations like
>
> %rest:query-param("client", "{$client}", "unknown")
>
> which can repeat with different values of the first argument.
>
> I don't think it relies on the annotations being ordered.
>
> Michael Kay
> Saxonica
>
>
>> On 12 Oct 2016, at 11:08, Michael Kay <mike@saxonica.com> wrote:
>>
>> Note that in XSLT, the nearest equivalent to XQuery's function annotations would be user-defined attributes on an xsl:function element. In this case it would definitely be the case that the annotations have distinct names and are unordered.
>>
>> We need to maintain the principle that the data model is common between XSLT and XQuery.
>>
>> Michael Kay
>> Saxonica
>>
>>
>>> On 12 Oct 2016, at 11:00, Michael Kay <mike@saxonica.com> wrote:
>>>
>>> I've had input from a user who wants to get information about the annotations on a function.
>>>
>>> Annotations don't seem to be part of the data model for function and we don't have any accessor functions that reveal the values of annotations.
>>>
>>> My first thought is that it's easy enough to meet this requirement with an extension function, and the obvious one would be something like
>>>
>>> function-annotations($f as function()) as map{xs:QName, item()*}
>>>
>>> But the same user points out that Saxon isn't allowing several annotations on a function with the same name, although the spec appears to permit this. If the data model allows several annotations with the same name then this complicates the API.
>>>
>>> So, a question: is it by design or by accident that we don't have any rule prohibiting multiple annotations on a function with the same name?
>>>
>>> If we do allow it, is the order significant? Would you expect the order in which annotations appear to be retained in such an API?
>>>
>>> Michael Kay
>>> Saxonica
>>>
>>
>>
>
>


-- 
John Snelson, Lead Engineer                    http://twitter.com/jpcs
MarkLogic Corporation                         http://www.marklogic.com

Received on Wednesday, 12 October 2016 10:50:42 UTC