The below is a REPL session using Rakudo.
> my Int $x = 1
1
> dd $x
Int $x = 1
Nil
Why is there a Nil on the second line of the output of dd?
> sub mydd( $foo ) { dd $foo; "hello" }
&mydd
> mydd $x
1
hello
The Nil is the return value of dd, or lack thereof to be precise.
The REPL in Raku checks whether the code executed did any output to STDOUT. This is done with the assumption that if your code outputs something, that you would be interested in that, not the return value of the expression you just executed. So that is why:
> say 42
42
will only show 42 and not also show the return value of say (which happens to be True btw). It does not check STDERR. Check this with note:
> note 42
42
True
note is the same as say, but puts its output on STDERR instead of STDOUT. And the same applies to dd. So that's why you also get this with dd:
> dd 42
42
Nil
Except that the implementation of dd is returning Nil because it is intended as a debugging aid that should interfere as little as possible with its environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With