Q code example

I’ve been coding in the q language for the past few weeks. It’s an interesting beast and one that I have a hard time understanding many of the design decisions behind it. I try to convey just how obtuse the language is, but I thought a code sample might make things a little more clear.

This bit of code will convert a table to XML.

/given a value of type number, string or time, make an XML element with the type and the value
typedData:{typeOf:{(string`Number`String`Time)[0 10 13h bin neg type x]};”“,string[x],”“}

/ wrap a value around a tag
tagit:{[tagname; v] tagname: string [tagname]; “<”,tagname,”>”, v,””};

/convert a table (of numbers, strings and time vaues) into xml
toxml:{ f: {flip value flip x}; colNames: enlist cols x; tagit[`worksheet]tagit[`table]raze(tagit[`row] raze tagit[`cell] each typedData each)each colNames,f x}