Skip to content
Permalink
Browse files

Fix List.perl for lazy lists

- fixes #2892
- now shows first 100 elements of lazy list, like with .gist
- postfixes .lazy for lazy lists
- removed hack from dd for handling lazy lists
  • Loading branch information...
lizmat committed May 14, 2019
1 parent ea94966 commit ec97878005e2cce8288d9b1afa5fe8107b410194
Showing with 25 additions and 10 deletions.
  1. +4 −6 src/core/Any.pm6
  2. +21 −4 src/core/List.pm6
@@ -572,12 +572,10 @@ sub dd(|) {
while $args {
my $var := nqp::shift($args);
my $name := ! nqp::istype($var.VAR, Failure) && try $var.VAR.name;
my $type := $var.WHAT.^name;
my $what := nqp::can($var, 'is-lazy') && $var.is-lazy
?? $var[^10].perl.chop ~ "... lazy list)"
!! nqp::can($var, 'perl')
?? $var.perl
!! "($var.^name() without .perl method)";
my $type := $var.WHAT.^name.split("::").tail;
my $what := nqp::can($var,'perl')
?? $var.perl
!! "($var.^name() without .perl method)";
note $name ?? "$type $name = $what" !! $what;
}
}
@@ -867,10 +867,27 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP

multi method perl(List:D \SELF: --> Str:D) {
SELF.perlseen('List', {
'$' x nqp::iscont(SELF) ~ '('
~ (self.elems == 1 ?? self[0].perl ~ ',' !! self.map({.perl}).join(', '))
~ ' ' x nqp::istrue(self.not && nqp::iscont(SELF)) # add space to avoid `$()`
~ ')'
my $prefix := nqp::iscont(SELF) ?? '$(' !! '(';
if self.is-lazy {
my @elements = self.head(101);
if @elements > 100 {
@elements.pop;
$prefix ~ @elements.map({.perl}).join(', ') ~ '...).lazy';
}
else {
$prefix ~ @elements.map({.perl}).join(', ') ~ ').lazy';
}
}
elsif self.elems -> $elems {
$prefix ~ (
$elems == 1
?? self[0].perl ~ ',)'
!! self.map( {.perl} ).join(', ') ~ ')'
)
}
else {
$prefix ~ (nqp::iscont(SELF) ?? ' )' !! ')')
}
})
}

0 comments on commit ec97878

Please sign in to comment.
You can’t perform that action at this time.