CHAPTER 10Parse Trees

Parse trees are an essential internal construct of the q language. They are a nested list – or collection – of functions and their arguments, which can be executed when desired and are expressed in the form of (func;arg1;arg2;...). They reflect the images-calculus philosophy of q. Every argument of such a function may be a function itself and any q query can be expressed as a series of nested functions. Those functions – the nested queries – can be evaluated whenever they are called, and they can be overloaded, reacting differently based on the types of their arguments. The parse tree thus represents an internal functional representation within the q language.

The ability to represent any query as a function (or nested functions) gives us more flexibility when working with data. This is particularly handy for expressions which manipulate tables, the cornerstone of the query language. Let us take select as an example:

image
image

This basic query makes perfect sense to us, and we can easily construct a number of similar queries. What if we want to have the selected columns or where constraints parameterised to be dynamic based on our desired input? The tools explored so far do ...

Get Machine Learning and Big Data with kdb+/q now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.