XPath as a stand-alone programming language (Was: Re: [xsl] [Summary]XPath 3.0 is a composable language ... what does that mean?)

From: Dimitre Novatchev <dnovatchev@gmail.com>

To: xsl-list@lists.mulberrytech.com, xml-dev@lists.xml.org

Date: Wed, 24 Oct 2012 06:32:29 -0700

A few months ago I had the pleasure to do "all XPath programming".
I developed the Binary tree data type and the Set data type
essentially completely in XPath 3.0.
These can be found in my blog, respectively at:
http://dnovatchev.wordpress.com/2012/01/09/the-binary-search-tree-data-structurehaving-fun-with-xpath-3-0/
and
http://dnovatchev.wordpress.com/2012/01/12/the-set-datatype-implemented-in-xpath-3-0/
At the time this happened accidentally. I don't like to work with
XQuery, but at that time Saxon's XSLT 3.0 processor didn't fully
implement higher order functions. Saxon's XQuery 3.0 did, so I
reluctantly used XQuery 3.0 in my work. Doing so, I planned to move my
whole code to XSLT 3.0 --whenever Saxon's XSLT 3.0 processor was ready
for this (and now, in version 9.4 it is). Therefore I essentially
coded everything as much in pure XPath 3.0 as possible.
This experience clearly showed to me that it is possible to use XPath
3.0 as a stand-alone programming language. This has many benefits, and
one of them is that XPath-only code is fully transferrable between
XSLT and XQuery.
At the end of my latest blog post "Recursion with anonymous (inline)
functions in XPath 3.0", I list a number of nice features we still
need in XPath as a programming language, that could be added in a
future, post-3.0 version:
1. Stand-alone XPath processors.
2. Import/include directives for XPath-only files (expression-files).
3. Separate packaging/compilation of XPath-only programs.
4. New data structures such as tuples.
5. Generics – parametric data types.
Cheers,
Dimitre
On Wed, Oct 24, 2012 at 4:55 AM, Costello, Roger L. <costello@mitre.org> wrote:
> Thanks a lot Michael for the explanation. Fantastic!
>
> Below is a summary of my question plus Michael's answer (slightly expanded).
>
> The XPath 3.0 specification says this:
>
> XPath 3.0 is a composable language
>
> What does that mean?
>
> It means that every operator and language construct allows any XPath expression to appear as its operand (subject only to operator precedence and data typing constraints).
>
> For example, take this expression:
>
> 3 + ____
>
> The plus (+) operator has a left-operand, 3. What can the right-operand be? Answer: any XPath expression! Let's use the max() function as the right-operand:
>
> 3 + max(___)
>
> Now, what can the argument to the max() function be? Answer: any XPath expression! Let's use a for-loop as its argument:
>
> 3 + max(for $i in 1 to 10 return ___)
>
> Now, what can the return value of the for-loop be? Answer: any XPath expression! Let's use an if-statement:
>
> 3 + max(for $i in 1 to 10 return (if ($i gt 5) then $i*3 else $i*2)))
>
> The fact that XPath is a composable language is very cool and very powerful.
>
> Contrast this with XSLT, which is not fully composable: XPath expressions can be used as operands to XSLT instructions, but not the other way around. Similarly Java has constructs called statements that
> cannot be nested inside expressions.
>
> /Roger
>
> --~------------------------------------------------------------------
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@lists.mulberrytech.com>
> --~--
>
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.