I understand white space matters in q code. Where does it matter?

  • The first character before a ‘/’ that begins a comment must be whitespace (newline is OK).
  • Every line after the first in a multiline expressions must be indented.

The latter rule applies, for example, to functions. The following is not valid q:

f: {[x] x}

Even a function’s closing brace must be indented if it appears on a line by itself:

f: {[x] x

Function definition is not the only time you have to be careful to follow this rule, however. In the following example, g is not the list (47; 48); rather, g is a projection of the comma operator with its first argument set to 47:

g: 47,

1 Comment

  1. Mike Rosenberg
    October 3, 2011 / 5:12 pm

    here's another (obscure) place where white space matters:

    q)f:{[x] -1″x is “,string x;} /you need the space between the ] and the –
    x is 12
    q)f:{[x]-1″x is “,string x;} /this will fail

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This work is licensed under a Creative Commons License.
The views and opinions expressed herein are those of the authors and do not necessarily reflect those of any other person or legal entity.
Kdb+ is the registered trademark of Kx Systems, Inc.