[xquery-talk] function declaration vs expression

W.S. Hager wshager at gmail.com
Mon Mar 14 21:48:57 PST 2016


Ah right, you can't overload a variable of course.

Op maandag 14 maart 2016 heeft Ghislain Fourny <g at 28.io> het volgende
geschreven:

> Hi WS,
>
> Higher-order functions were added in XQuery 3.0 so that you can build
> them dynamically (using closures) and pass them as parameters like any
> other items.
>
> I see little benefit in defining your function as a variable
> declaration with an inline function expression vs. a static function
> declaration such as
>
> declare function local:id($x) {
>   $x
> };
>
> You can reference the former with $local:id and the latter with
> local:id#1 to make them flow around as function items. You can call
> the former with $local:id($x) and the latter with local:id($x). The
> former has no name, the latter has a name (local:id).
>
> When you need a function that dynamically depends on the value of a
> variable at runtime, however, you will need to use inline function
> expressions. Variables in scope will be added to the closure of the
> created function item.
>
> I hope it helps!
>
> Kind regards,
> Ghislain
>
> On Mon, Mar 14, 2016 at 2:48 PM, W.S. Hager <wshager at gmail.com
> <javascript:;>> wrote:
> > Hello,
> >
> > What is the difference between a function declaration and a function
> > expression in a variable declaration, eg:
> >
> > declare variable $local:id := function($x) { $x }
> >
> > and why does it exist?
> >
> > --
> >
> > W.S. Hager
> > Lagua Web Solutions
> > http://lagua.nl
> >
> >
> > _______________________________________________
> > talk at x-query.com <javascript:;>
> > http://x-query.com/mailman/listinfo/talk
>


-- 

W.S. Hager
Lagua Web Solutions
http://lagua.nl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20160315/c15d8633/attachment.html>


More information about the talk mailing list