James,
Thanks for the tests. They're in the repository now. I fixed the 05 to
better illustrate the usage of reform(), also added some docs to
list.pm regarding same and added t/06... to show usage of references to
named subs.
# from James E Keenan
# on Sunday 26 February 2006 05:03 pm:
> I don't really understand reform() -- particularly: what
>goes inside the code ref. Is this how I would use it?
No. Basically, you want to use reform any time where you would
otherwise have to break the chain and call
L(that_sub($l->map(\&f1)))->map(\&f2);
Instead, you can
$l->map(\&f1)->reform(sub {that_sub(@_)})->map(\&f2);
> [EMAIL PROTECTED] = qw(abel abel baker camera delta edward fargo golfer);
> $l = L(@a0);
> $reform = $l->reform( sub { return $_ } );
I hope the new docs help clarify that. I notice the tendency to put $_
in a reform sub, which is incorrect. These subs only see @_ (but IIRC,
$_ is not undef and therefore this caused me a silent error yesterday
when I made the same mistake (maybe I should localize $_ as undef?))
Is there a better name than reform? My intent was to use it when e.g.
you wanted to break a flat list into several nested array refs -- a
case where $_ per-element processing is not possible (you need to pass
the entire list and return an entirely new one.) Thus the name choice,
but maybe it should be something more explicitly in contrast to map
(just to brainstorm a bit)
(
pam (reverse?),
spam (nope),
mold (hmm),
remap (nah),
dice (hey!),
apipe,
hoop (huh?),
mop,
through (i.e. run-through),
preach (process each),
)
It's sort of a macro-level mapper, or maybe you could see it as a list
eval, but I don't really like the name leval and I'm saving eval for
something more like CORE::eval. Of my favorites, mop is too
one-character-away, dice has a nice ring to it, and apipe (array pipe)
is kind of cool, but implies too much about "\n" delimiters and/or
per-element processing when taken in the context of shell pipes. Maybe
dice is the one (as in: you can do things with dice that you can't do
with slice.)
Thanks,
Eric
--
Like a lot of people, I was mathematically abused as a child.
--Paul Graham
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------