Hacker News new | ask | show | jobs
by hoytech 2712 days ago
It's pretty much exactly like Ingy's XXX perl module from 2006: https://metacpan.org/pod/XXX

Prints a YAML dump of "my str", followed by file/line number information, then returns its argument so it can be embedded in expressions:

    $ perl -MXXX -E 'say uc(WWW("my str"))'
    --- my str
    ...
      at -e line 1
    MY STR
Data::Dump's "ddx" (1996) is also commonly used for print debugging, except it doesn't return the argument.
1 comments

Almost. dbg! also shows the statement in addition to what it evaluates too. That is:

  dbg!(n * factorial(n - 1))
shows up as:

  [src/main.rs:5] n * factorial(n - 1) = 2
  [src/main.rs:5] n * factorial(n - 1) = 6
  [src/main.rs:5] n * factorial(n - 1) = 24
Although, IIRC there was some crazy dumper module by dconway (who else) that worked similar to this, but I don't recall if it returned the value.

...

So, I just looked it up, and I found it. Actually, Damien wrote two. One that he updated from 2014 to 2016, and one he started in 2017 and has maintained to the present. I have no idea the reason for that.

1: https://metacpan.org/pod/Data::Show

2: https://metacpan.org/pod/Data::Dx

Hehe nice ones, thanks for the links! :)

Yep leave it Damien. I remember he did something similar for a test module where it would show the expressions that were evaluated in the test failure output.