>
> >Damian Conway [mailto:[EMAIL PROTECTED]] wrote:
> >
> >You *could* instead consider reversing the arguments to
> all the list
> >manipulation operators:
> >
> > @result = map @data { mapping() }
> > @result = grep @data { selector() };
> > @result = sort @data { comparison() };
> > @result = reduce @data { combinator() };
> >
What about:
$result = join @data, "";
It might not be a list manipulation operator, but people
are going to get awfully confused if it isn't changed to
this. Why should:
$result = join "", @data;
but:
$result = map @data { "$_" };
Personally, I am biased since I rather like the
map/sort/map type thing - looking at the data being
manipulated from the bottom upwards.
@result = map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [$_, hash($_)] }
@data;
I like my indentation better too :P
>
> I would love this. From an OO point of view, it
> looks much more natural imho to think on map and
> friends as list methods that take block arguments
> than as block methods that take arrays as arguments.
I disagree on the basis of what it'll do to something like
join. It is far more readable to have:
$result = join " ", "first", "second", "third";
than:
$result = join "first", "second", "third", " ";
since in the second version the joining character(s) is
near the end. Usually if reading code you want to find out
quickly what character(s) is being used.
> In other words:
>
> @result = @data.map(&mapping)
>
> looks better than:
>
> @result = &mapping.map(@data)
>
Can't the first version be make valid without that
modification to order of map/sort etc?
> Mmm.. If we did reverse the order of the arguments I was
> expecting it to
> become:
>
> @sorted_by_size =
> @files.map({ [$_, -s] })
> .sort({ $^a[1] <=> $^b[1] })
> .map({ $_[0] })
Or basically:
@sorted = @files
.map ({ [$_, -s] })
.sort({ $^a[1] <=> $^b[1] })
.map ({ $_[0] })
Lovely, data goes in at the top and actions are processed
from the bottom up... at least according to how I currently
think of map/sort/map. Is this OOPism worth the pain to
the rest of us?
Jonathan Paton
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com