I’m used to sprinkling print statements to debug my code. How can I do the same in q?

Like printf, 0N! is your friend. When you place 0N! before an expression, it prints the result of that expression to the console and then returns it:

q)1 + 0N! til 10
0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10

0N! does change the functionality of your code in one subtle, albeit usually harmless, way. If you place 0N! before a modifier-assignment operator (e.g. +:, -:), then the result of that assignment is no longer null; it is the value assigned:

q){x +: 47} 1
q){0N! x +: 47} 1

See also: .Q.s and .Q.s1


  1. Harshal
    July 24, 2013 / 12:51 pm

    You people are awesome.

  2. jithinr77
    September 30, 2017 / 11:29 am

    If I have a table called tbl2 and I do 0N!tb2 I will get the code to recreate this table and then the table. Which can be useful If I want to share that code with someone else and they can recreate the table. How can I get the same code when the output will be too long for stdout. I have set the limit to max but the output will still be too long.

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.