Fun With XQuery

by Jason Booth

Recently on a flight, I decided to put an idea to the test with programming in XQuery. I wanted to write a simple logic puzzle of some sort – what I ended up doing was writing a simple card dealing program. XQuery 1.0, along with MarkLogic extensions to the language (the “xquery version 1.0-ml” dialect), provides some great programming capabilities. The following example shows the usage of maps, recursion, logging (via xdmp:log()), random numbers (via xdmp:random()) and side effects (via xdmp:set()).
Why I don’t expect that a poker site, nor the latest strategy game, will be written in XQuery, it is refreshing to see any language used for something you normally wouldn’t use it for. Often, when doing so a developer can learn something new about a language when they look at it in a different context. Also, I hope the following example will show those new to XQuery a look at the language that they may not get to see in other tutorials or examples.