Wednesday, October 9, 2013

Quick Tip: Intra-Statement Breakpoints

A statement referencing a non-existent variable is a common way to add a breakpoint to a q function.
q)f:{x:x+1;break;x+2}
While this is handy, it only lets you break between statements. A simple extension lets you break within statements, inspecting values at arbitrary points in the code, and continuing with execution once you’re done:
q)f:{x:x+1;{break;x}x+2}
Now, the break will occur after the portion of the statement to the right of the break function has executed, and x within the break function will have the value returned by that code. Since the break statement itself has no effects, and x contains the value returned by the code executed so far, typing : to continue will allow the rest of the break function to execute, returning x leftwards and allowing the rest of the statement to execute as if nothing had interrupted it.

Note that this is entirely legal inside qsql queries; I’ve often found it of particular utility there, since you can’t create new local variables inside a query. Unfortunately no specific examples come to mind at the moment; I’ll try to post one later to make it clearer how this technique works.

Labels: ,

Monday, March 11, 2013

My kdb+ User Meeting Presentation

Here are the slides from the presentation I gave today at the kdb+ user meeting at BAML, in keynote, pdf, and powerpoint formats:
UPDATE: and here's the code as a loadable .q file:

Labels: ,

Monday, June 4, 2012

What the Function?!?

q is notorious for its limited debugging features. One prominent aspect of this is the way runtime errors in the interactive shell are handled: you enter the debug shell and are presented with the body of the function that failed and the error that occurred. What’s missing? The name of the function!

So, to fill that gap, I’ve written a function wtf[] which will search the workspace for its argument, returning a fully-qualified name if it finds anything. wtf, along with brief documentation and a couple examples, can now be found in the lib subdirectory of my contrib (a section I hope to expand in the future).

Labels: ,