XQuery and Literate Programming

by Chris Wallace

"One thing leads to another" might be the sub-title for the web. Last night I found myself by some circuitous route in LiteratePrograms, a wiki set up by Derrick Coetzee. The site incorporates a version of that earlier WEB. Donald Knuth's tangle and weave programs allow a single literate program script to be transformed to a view which make sense to the compiler and another which makes sense to a human reader.

The wiki is a laudable effort to provide code examples, clearly explained in many languages but it is fighting a bad case of spam. Comparative examples is a valuable educational resource to show how to abstract away the specifics of a syntax to see through to the essential similarities and differences. No examples in XQuery and only a couple in XSLT however, so here's another opportunity for an XQuery evangelist.

Fibonacci is the computer science 'hello world'. It is well represented in the wiki in numerous languages and many algorithms. The lack of a higher order factoring of the many algorithms away from the code needs tackling. XQuery with its limited functional model, lacking such devices as higher order functions, lazy evaluation, closures and generators, restricts the algorithms to pure recursive functions. When coming to XQuery from a background in imperative, object-oriented languages, the loss of updating variables is quite a challenge. .Good old Fib is not a bad example to start with.


Dan McCreary
2008-06-03 13:24:39
Brilliant! You have demonstrated the XQuery is clearly ready to join the big leagues as a server-based language. It is so much more then SQL will every be but it has the same data selection power. Your use of Google Charts with a simple ReST interface shows how small and elegant XQuery can be.

Bravo Chris!