Skip to content

ER: debug/1 #2709

@pkoppstein

Description

@pkoppstein

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions