Changes

Jump to navigation Jump to search
1,228 bytes added ,  19:11, 21 February 2012
==Function Items==
Various languages One of the most distinguishing features that 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 writing 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 oder user-defined) XQuery function. The arity (number of arguments) has to be specified as there can be more functional are already completely implemented than one function with the same name:<pre class="brush:xquery">let $f := math:pow#2return $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 BaseXthe positions of the arguments left out. The produced function item has one argument for every placeholder.<pre class="brush:xquery">let $f := fn: functions substring(?, 1, 3)return ( $f('foo123'), $f('bar456'))</pre> '''Result:''' <code>foo bar</code></li></ul> Function items can now also be dynamically invocated, inlined and passed on as arguments to other and returned as results from functions. These so called ''higher-order'' functionslike fn:map and fn:fold-left will soon be discussed in more depth on their own Wiki page.
==Serialization==
editor, reviewer
33

edits

Navigation menu