Changes

Jump to navigation Jump to search
No change in size ,  11:11, 10 November 2015
no edit summary
More information on window clauses, and all other enhancements, can be found in the [http://www.w3.org/TR/xquery-30/#id-windows specification].
 
=Function Items=
 
One of the most distinguishing features added in ''XQuery 3.0'' are ''function items'', also known as ''lambdas'' or ''lambda functions''. They make it possible to abstract over functions and thus write more modular code.
 
'''Examples:'''
 
Function items can be obtained in three different ways:
 
<ul>
<li>Declaring a new ''inline function'':
<pre class="brush:xquery">let $f := function($x, $y) { $x + $y }
return $f(17, 25)</pre>
'''Result:''' <code>42</code>
</li>
<li>Getting the function item of an existing (built-in or user-defined) XQuery function. The arity (number of arguments) has to be specified as there can be more than one function with the same name:
<pre class="brush:xquery">let $f := math:pow#2
return $f(5, 2)</pre>
'''Result:''' <code>25</code>
</li>
<li>''Partially applying'' another function or function item. This is done by supplying only some of the required arguments, writing the placeholder <code>?</code> in the positions of the arguments left out. The produced function item has one argument for every placeholder.
<pre class="brush:xquery">let $f := fn:substring(?, 1, 3)
return (
$f('foo123'),
$f('bar456')
)</pre>
'''Result:''' <code>foo bar</code>
</li>
</ul>
 
Function items can also be passed as arguments to and returned as results from functions. These so-called [[Higher-Order Functions]] like <code>fn:map</code> and <code>fn:fold-left</code> are discussed in more depth on their own Wiki page.
=Simple Map Operator=
</pre>
'''Result:''' <code>red red</code>
 
=Function Items=
 
One of the most distinguishing features added in ''XQuery 3.0'' are ''function items'', also known as ''lambdas'' or ''lambda functions''. They make it possible to abstract over functions and thus write more modular code.
 
'''Examples:'''
 
Function items can be obtained in three different ways:
 
<ul>
<li>Declaring a new ''inline function'':
<pre class="brush:xquery">let $f := function($x, $y) { $x + $y }
return $f(17, 25)</pre>
'''Result:''' <code>42</code>
</li>
<li>Getting the function item of an existing (built-in or user-defined) XQuery function. The arity (number of arguments) has to be specified as there can be more than one function with the same name:
<pre class="brush:xquery">let $f := math:pow#2
return $f(5, 2)</pre>
'''Result:''' <code>25</code>
</li>
<li>''Partially applying'' another function or function item. This is done by supplying only some of the required arguments, writing the placeholder <code>?</code> in the positions of the arguments left out. The produced function item has one argument for every placeholder.
<pre class="brush:xquery">let $f := fn:substring(?, 1, 3)
return (
$f('foo123'),
$f('bar456')
)</pre>
'''Result:''' <code>foo bar</code>
</li>
</ul>
 
Function items can also be passed as arguments to and returned as results from functions. These so-called [[Higher-Order Functions]] like <code>fn:map</code> and <code>fn:fold-left</code> are discussed in more depth on their own Wiki page.
=Expanded QNames=
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu