On Mon, Apr 08, 2013 at 10:54:47AM -0400, Ricker, William wrote:
> Have we mentioned the other solution? 
> The Implicit loops of map {block} list; should produce more optimized code 
> and reads better too. 

map should produce better code and does reads better but it also iterates
the entire list and you can't break out of it. I think it's only a viable
solution in the limited case of a for loop that doesn't have a stopping case
or filtering.

Well, the filtering part is not really true: it could be more expensive to say

   @result = map {BLOCK} grep {PREDICATE} @list;

than

  my @result;
  for my $element (@list) {
    push @result, $element if PREDICATE;
  }

but the former simply reads better and, in the absence of other necessities, I 
prefer it.

As for recursion, I don't think one can easily replace a recursive solution
with map. Replacing recursion with iteration requires a base 
condition (and, possibly, a stack) and map doesn't handle stopping conditions.
One could work around it, I suppose, but not cheaply and the code would almost
certainly be tasteless.

-Gyepi

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to