Next: , Up: Query Construction   [Contents][Index]


9.1 Prefix-Style Expressions

To be brutally honest, both SQL and Scheme revolve around structured expressions (also known as sexps), so ascribing some elevated status to the representation that “supports sexps” is really not saying much. In the Guile-PG maintainer’s humble opinion, the advantage in expressiveness of Scheme over SQL is not in the presence or lack of structure, but rather in the regularity of the structure.

Scheme syntax is (as you probably already know) exceedingly easy to describe: first there is the opening parenthesis, then the operator or function, then the argument(s), and finally the matching closing parenthesis. The argument(s) can in turn be sub-expressions of their own. This simplicity stands in stark contrast to the myriad rules (and worse: exceptions to the rules) that comprise the SQL language specification.

Thus, we call the mini-language described in this chapter prefix-style expressions because it borrows from Scheme’s regularity even though it is not Scheme, per se. This is the general form of a prefix-style expression:

(operator [operand ...])

In words: An open parenthesis followed by a symbol operator followed by zero or more operand arguments, each in turn a prefix-style sub-expression, followed by the close parenthesis. Components of these expressions may be symbols, keywords, numbers, strings and matching parentheses. Unlike Scheme, there is no quote, quasiquote, unquote or unquote-splicing, although those facilities can (and should) be used in a Scheme program to construct a prefix-style expression. Also unlike Scheme is the requirement that operator be a symbol; it is not processed in the same way as each operand.

Usually, operator names an SQL function or operator. For example, the symbol date_trunc refers to the SQL function by the same name. Guile-PG uses lookup tables to determine how to transform the prefix style into either infix, postfix, functional or other layouts.


Next: Special Operators, Up: Query Construction   [Contents][Index]