Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make dd a little more useful for natives
If you specify dd $a, and $a is a native int or str, then you only get
to see the value *without* the name.  This is annoying while debugging.
To make this easier, you can now specify natives as a named parameter.

  my int $a = 42; dd :$a;   # Int a = 42

and by the magic of the :$var notation, we can now see the name.
  • Loading branch information
lizmat committed Oct 21, 2015
1 parent 009400e commit c85c7c6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/core/Any.pm
Expand Up @@ -511,18 +511,23 @@ sub DELETEKEY(Mu \d, str $key) {
}
} #DELETEKEY

sub dd(|) {
my Mu $args := nqp::p6argvmarray();
if nqp::elems($args) {
while $args {
my $var := nqp::shift($args);
sub dd(*@p, *%n) {
if @p || %n {
for @p -> $var {
my $name := $var.VAR.?name;
my $type := $var.WHAT.^name;
my $what := $var.?is-lazy
?? $var[^10].perl.chop ~ "...Inf)"
!! $var.perl;
note $name ?? "$type $name = $what" !! $what;
}
for %n.kv -> $name, $var {
my $type := $var.WHAT.^name;
my $what := $var.?is-lazy
?? $var[^10].perl.chop ~ "...Inf)"
!! $var.perl;
note $name ?? "$type $name = $what" !! $what;
}
}
else { # tell where we are
note .name ?? "{lc .^name} {.name}" !! "({lc .^name})"
Expand Down

0 comments on commit c85c7c6

Please sign in to comment.