NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
returning refs? (Score:1)
Why not return []'s which get flattened into the output until undef is returned?
my @rev = induce {@$_ ? pop @$_ : undef} [1..10];
But maybe I'm missing something as to why the prototype is &$ instead of &@, or am just wanting a better example? I would think that unfold might be more like:
my @flat = map({map({$_} @$_)} [1..10],[12..20]);
or thereabouts - and the 'reverse' example does not clarify that for me.
Re: (Score:1)
Because then there has to be an escape mechanism for the block to be able to return an actual
[]that should be preserved in the output, and the block has to make sure to use it when appropriate.Because unfold (“induce”) takes a single value and inflates it to a list, as opposed to fold (reduce) which takes a list and def
Re:returning refs? (Score:1)
Why not return []’s which get flattened into the output until undef is returned?
Because then there has to be an escape mechanism for the block to be able to return an actual [] that should be preserved in the output, and the block has to make sure to use it when appropriate.
No, you would not reach inside the returned ref - only flatten it at the first level. It is either [] or undef, so [[]] would be a list of one reference.
my @power = induce {
my $r = $_ % 12
$_
return $r ? [$r] : undef;
} 4711;
my @chunk = induce {
(length) ? [substr $_, 0, 3, ''] : undef
} "foobarbaz";
The
return $condition ? [@stuff] : undefseems like it might be forming a pattern.Reply to This
Parent