Capability | Presence | Remarks |
---|---|---|
Define | No. | Variables references can be part of XPath 1.0 expressions,
but such variables must be defined by the host language
(various PLs, DOM, or XSLT[ |
Define and use | No. | In an XSLT context the function current() provides a limited capability
of an outer-context variable.
|
Define its | No. | Only XPath system functions or functions defined in the host-provided context
(such as generate-id() ) can be referenced.
|
Work with | No. | Only the notion of a |
Define own | No. | |
Specify that a function should be executed on every selected node. | No. | |
Strong typing. | No. | XPath 1.0 is a weakly-typed language. |
Capability | Presence | Remarks |
---|---|---|
Define | Yes, but limited. | Variables can be defined within an XPath 2.0 expression. It is impossible to define a variable whose value is a sequence. |
Define and use | Yes. | |
Define its | No. | Only XPath system functions or functions defined in the host-provided context
(such as functions defined in XSLT[ |
Work with | Yes. | XPath 2.0 supports sequences whose items can be non-nodes, or nodes that can occur more than once and/or in any order. |
Define own | No. | |
Specify that a function should be executed on every selected node. | Yes. | /a/b/c/string-length() is legal |
Specify that a function should be executed on every item in a sequence. | No. | While /a/b/c/string-length() is legal, it isn’t allowed to use:
('London', 'New York', 'Paris')/string-length()
|
Strong typing. | Yes. | XSD type constructors, cast as , castable as , instance of
|
Capability | Presence | Remarks |
---|---|---|
Define | Yes. | In addition to the variable definition available in XPath 2.0, XPath 3.0 makes it possible to define in a “let clause” a variable whose value is a sequence. |
Define and use | Yes. | As in XPath 2.0. |
Work with | Yes. | As in XPath 2.0. |
Define own | Yes. | Inline function items. |
Specify that a function should be executed on every selected node. | Yes. | As in XPath 2.0. |
Specify that a function should be executed on every item in a sequence. | Yes. | The ! (simple mapping) operator. |
Strong typing. | Yes. | As in XPath 2.0. |
Define its | Yes. | This is one of the most significant new features of XPath 3.0,
based on the “function item” type as defined in the XDM[ |
Higher Order Functions (HOFs). | Yes. | A function item is a first class object. It can be passed as a parameter or returned as a result of calling a function. It is possible to express such well-known FP techniques as functional composition, partial function application, creation of closures. |
Can recursive anonymous functions be specified within an XPath expression? | Yes. | Shown later in this paper. |
Can robust recursion of anonymous functions be implemented? | Yes. | Shown later in this paper. |
Can a new XML document or node be created within an XPath expression? | Yes. | Shown later in this paper. |
Can new data types be created in an XPath expression? | Yes. | Shown later in this paper. |
3
. $incr
variable. The
function definition has a strongly typed argument and a strongly typed result – in
this case both the argument and the result must be of type xs:integer
. xs:integer
return
clause. $process()
takes two arguments: a string, and a function
that takes a string and produces a string. The result returned by
$process()
is a string. let
clause two functions are defined, each taking
a string and producing a string: $lower()
and $reverse()
. $process()
is called twice, with “HELLO” as the
same first argument, and with the $lower()
function as the second
argument in the first call to $process()
and $reverse()
function as the second argument in the second call to $process()
. g(x)
and h(y)
is a third function f(x)
such that f(x) = h(g(x))
“ Partial function application is the ability to take a function of many parameters and apply arguments to some of the parameters to create a new function that needs only the application of the remaining arguments to produce the equivalent of applying all arguments to the original function.”
g(x)
, such that for all allowed values of x
the following holds:
increment()
function
in the following way:
3
.
$plus()
on
binding its first argument to 1
is defined simply as:
?
’ character is
called $greet()
returns as its result the inner
function and injects into the body of the inner function some of its own (outer
function’s) data – the value of its $greeting
argument.
$author()
) is created by the function
$lookup()
by injecting into it some of its own content – the top
element of the XML document to be searched. The result is:
n
, produces the value of n!
(The
factorial of n
).
$F
, which given an
argument $n
, produces $n!
n
, we run into problems when n
becomes bigger. 1
to 10
–
the result is: “In computer science , atail call is asubroutine call that happens inside another procedure as its final action; it may produce a return value which is then immediatelyreturned by the calling procedure. Thecall site is then said to be intail position , i.e. at the end of the calling procedure. If any call that a subroutine performs, such that it might eventually lead to this same subroutine being called again down the call chain, is in tail position, such a subroutine is said to betail-recursive ”
Log2(N)
— thus
for processing a sequence with 1M
(one million elements) the maximum
recursion depth is just 19
.
O(log2N) . seq1 and seq2 and if seq2 is
1000000 (1M) times longer than seq1 , the time
for processing seq2 is around one million times bigger, than
the time for processing seq1 . bst1
and bst2 , where bst2 has 1000000 (1M)
times more data items (nodes) than bst1 – in this case the time
to process bst2 is only 19 times bigger than the
time for processing bst1 . |
start date >= 2012-03-15
, end date <= 2012-05-15
):
|
find-range-of-transactions
. This is a recursive
function. As shown previously, implementing recursion using anonymous functions requires
a “helper” function. Here is the helper function
find-range-of-transactions-helper()
: