Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reality check

7 views
Skip to first unread message

Juerd

unread,
Feb 4, 2005, 4:39:30 PM2/4/05
to perl6-l...@perl.org
Does this make sense?

my @words = gather {
for =(open '/usr/share/dict/words' err die) {
.=chomp;
next if /<-[a-z]>/;
/$re/ and take { word => $_, score => %scores{ .letters }.sum };
}
} ==> sort { .<score> } is descending, { .<word>.length }, { .<word> };


Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html

Michele Dondi

unread,
Feb 7, 2005, 5:45:05 AM2/7/05
to Juerd, perl6-l...@perl.org
On Fri, 4 Feb 2005, Juerd wrote:

> Does this make sense?
>
> my @words = gather {
> for =(open '/usr/share/dict/words' err die) {
> .=chomp;
> next if /<-[a-z]>/;
> /$re/ and take { word => $_, score => %scores{ .letters }.sum };
> }
> } ==> sort { .<score> } is descending, { .<word>.length }, { .<word> };

With some effort I managed to understand _which_ sense it should make up
to this:


> } ==> sort { .<score> } is descending, { .<word>.length }, { .<word> };

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I mean: everything of what is gather()ed gets 'piped' into sort() which
sorts according to C<< { .<score> } >>. But what are the other args to it
supposed to mean? (Sorry for being dense!)


Michele
--
> i need to know what type of math and how much math a surgeon uses.
How about asking what type of surgery and how much surgery
a mathematician uses?
- Robin Chapman in sci.math

Juerd

unread,
Feb 7, 2005, 7:17:27 AM2/7/05
to Michele Dondi, perl6-l...@perl.org
Michele Dondi skribis 2005-02-07 11:45 (+0100):

> With some effort I managed to understand _which_ sense it should make up
> to this:
> > } ==> sort { .<score> } is descending, { .<word>.length }, { .<word> };
> I mean: everything of what is gather()ed gets 'piped' into sort() which
> sorts according to C<< { .<score> } >>. But what are the other args to it
> supposed to mean? (Sorry for being dense!)

Since I sent the message, I learned that if you want to sort with
multiple criteria, the first argument should be an arrayref of closures.

So what I should have written is:

==> sort [ { .<score> } is descending, { .<word>.length }, { .<word> } ];

And it's easier to write if a simple numeric minus is used:

==> sort [ { -.<score> }, { .<word>.length }, { .<word> } ];

This makes sort sort by score first, but if two words score equally,
word length will become important (score with as few letters as
possible, because there's a greater chance of succeeding within the time
limit). If the lengths are also equal, it sorts alphabetically, so
that words beginning with the same letter are grouped together.

Larry Wall

unread,
Feb 7, 2005, 2:20:58 PM2/7/05
to perl6-l...@perl.org
On Fri, Feb 04, 2005 at 10:39:30PM +0100, Juerd wrote:
: Does this make sense?

:
: my @words = gather {
: for =(open '/usr/share/dict/words' err die) {
: .=chomp;
: next if /<-[a-z]>/;
: /$re/ and take { word => $_, score => %scores{ .letters }.sum };
: }
: } ==> sort { .<score> } is descending, { .<word>.length }, { .<word> };

The other problem with this that = binds tighter than ==> does. Once you
start with pipes you probably want to stick with pipes:

gather {...} ==>
sort {...} ==>
my @words;

or

my @words <==
sort {...} <==
gather {...};

or just go back to the tried and true:

my @words =
sort {...}
gather {...};

Larry

0 new messages