[prev in list] [next in list] [prev in thread] [next in thread] 

List:       perl6-language
Subject:    Re: Counting characters
From:       Nicholas Clark <nick () ccl4 ! org>
Date:       2010-01-28 9:38:49
Message-ID: 20100128093849.GA14980 () plum ! flirble ! org
[Download RAW message or body]

On Wed, Jan 27, 2010 at 08:40:48AM -0800, Larry Wall wrote:
> On Wed, Jan 27, 2010 at 01:24:48PM +0000, Matthew Walton wrote:
> : On Wed, Jan 27, 2010 at 1:19 PM, Carl Mäsak <cmasak@gmail.com> wrote:
> : > Mark (>), Carl (>>):
> : >>> S05 describes tr/// in terms of the .trans function, a handsome but
> : >>> very different beast. Specifically, it doesn't seem to have a "scalar
> : >>> context", with which one could count things.
> : >>
> : >> What does trans return in numeric (+) context?
> : >
> : > As spec'd, it returns the numification of the string resulting from
> : > the substitution, I guess.
> : >
> : > // Carl
> : >
> : 
> : $str.comb(/C|G/).join('').chars might do it. It's maybe not quite as elegant...
> 
> Hmm, what might be more elegant?  Maybe something like...
> 
>     [+] $str.comb.Bag<C G>;
> 
> Probably does too much work building the Bag though, unless it can be
> lazy somehow.  But the point is that Bags are really just histograms
> with a cute name.

That or the optimiser is capable of recognising the entire construction, and
compiling it down to something efficient.

For example, how

   @a = sort @a;
   foreach (reverse @a) { ... }
   ... reverse sort { ... } ...
   if (%hash) { ... }

now work in Perl 5, by being optimised to a more efficient execution sequence.

Nicholas Clark
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic