Tagged: syntax
-
semi-colon in q scripts
Posted by kdb_newbie on May 31, 2025 at 11:05 amwhen is semi-colon needed in the q script and when is it not? thanks! I thought it’s needed everywhere but my script doesn’t error out
.ns.a:1;
.ns.b:2 //no semi-colon
.ns.c:3;pgyorok replied 4 hours ago 3 Members · 3 Replies -
3 Replies
-
Generally speaking each new line is a new statement (Note this is not valid inside a lambda and you need a trailing semicolon to separate expressions). You can use semicolons to separate expressions.
https://github.com/qbists/style/blob/main/semicolons.md
A good article to read is Stephen Taylor’s “Remarks on Style” https://github.com/qbists/style/tree/main
Personally, I prefer to use semicolons always when separating expressions
-
thank you, when are semi-colons necessary in q script? just at the end of function defintions?
-
When you load a script using \l, it is broken into blocks using a set of rules involving indentation and comments. Each block is then evaluated separately. A block doesn’t have to end in a semicolon, so if you have multiple unindented lines in a sequence, each of them will be its own block and not need a semicolon. However if you indent some of the lines (which is required for a multiline lambda), those become part of the same block with the previous non-indented line, so semicolons are necessary to separate the individual statements in the block.
Another important factor is that IPC doesn’t do the same block splitting, so if you use a tool such as KDB Studio, it will execute the entire code as a single block, therefore any missing semicolons could result in errors due to the different lines running together. For this reason I prefer to put a semicolon after every statement. Another benefit is that this prevents garbage from being printed on the console when loading the file.
-
Log in to reply.