Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ER: debug/1 #2709

Closed
pkoppstein opened this issue Jul 12, 2023 · 1 comment · Fixed by #2710
Closed

ER: debug/1 #2709

pkoppstein opened this issue Jul 12, 2023 · 1 comment · Fixed by #2710

Comments

@pkoppstein
Copy link
Contributor

pkoppstein commented Jul 12, 2023

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.

@itchyny
Copy link
Contributor

itchyny commented Jul 12, 2023

Ref: #2111, #2112

pkoppstein added a commit to pkoppstein/jq that referenced this issue Jul 13, 2023
This def ensures the output of debug(m1,m2) is kept together.

See jqlang#2709 jqlang#2111 jqlang#2112
@pkoppstein pkoppstein mentioned this issue Jul 13, 2023
pkoppstein added a commit to pkoppstein/jq that referenced this issue Jul 13, 2023
This def ensures the output of debug(m1,m2) is kept together.

See jqlang#2709 jqlang#2111 jqlang#2112

Update jq.1.prebuilt

manual.yml: debug/1: more typos

manual.yml: debug/1: typo

msgs
pkoppstein added a commit to pkoppstein/jq that referenced this issue Jul 13, 2023
This def ensures the output of debug(m1,m2) is kept together.

See jqlang#2709 jqlang#2111 jqlang#2112

Update jq.1.prebuilt

manual.yml: debug/1: more typos

manual.yml: debug/1: typo

msgs

builtin.jq: spacing
pkoppstein added a commit to pkoppstein/jq that referenced this issue Jul 13, 2023
This def ensures the output of debug(m1,m2) is kept together.

See jqlang#2709 jqlang#2111 jqlang#2112

Update jq.1.prebuilt

manual.yml: debug/1: more typos

manual.yml: debug/1: typo

msgs

builtin.jq: spacing

manual.yml: more tweaking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants