-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
There have been several proposals for adding debug/1 for convenience.
In particular, @nicowilliams mentioned:
def debug($msg): ("\($msg): \(.)|debug|empty), .;
This has good memory-management characteristics, but includes "(.)" unconditionally, which reduces flexibility and can lead to very long debug
messages that can potentially cause problems. Thus I would like to propose a similar but simpler definition:
def debug(msg): (msg | debug | empty), .;
This would allow tailored messages such as: debug("entering foo(\(arg1); \(arg2))")
while still allowing . to be prepended with a string, at a cost of just a few extra keystrokes:
debug("hello: \(.)")
Or one could go with:
debug("hello", .)
Footnote:
#2112 proposes:
def debug(f): . as $val | f | debug | $val;
but this def effectively presupposes that f is a singleton, for if
one were to use it and wrote debug("msg1"; "msg2")
, an undesirable fork would result.
The two defs above avoid this issue, and indeed make it easy to split up a debug message over more than one line, while keeping them together.