« Is there a free trial version of kdb available for download? | Main | How do I debug code in kdb? »

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
q)

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
48
48
q)

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

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (2)

You people are awesome.

July 24, 2013 | Unregistered CommenterHarshal

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.

September 30, 2017 | Registered Commenterjithinr77

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Textile formatting is allowed.