On Fri, 22 May 2009, Jonathan Worthington wrote:

Daniel Ruoso wrote:
Em Sex, 2009-05-22 às 01:25 -0500, John M. Dlugosz escreveu:

    @primes = do $_ if prime($_) for 1..100;
becomes
    @primes = $_ when prime($_) for 1..100;



you gained one stroke, it's certainly better... I think it's time to
play golf with Perl 6 already ;)

jokes aside, "$_ when prime($_)" looks more natural than "do $_ if
prime($_)"


Yes and:

@primes = 1..100.grep: { prime($^n) };

Is actually vaguely, like, readable AND two characters shorter than the best you've managed so far.

        Oh, if we're looking for readability, I'd look for:

1..100.grep: { prime($^n) } ==> @primes;

        It's longer, though :).


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: wayl...@wayland.id.au    | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI++++ D G+ e++>++++ h! y-
-----END GEEK CODE BLOCK-----

Reply via email to