Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • in the first version we compute .lc on each element only once for the entire sort, whereas in the second version it's computed once for each comparison.


  • Maybe this doesn't make sense but some way to stick with method calls appeals to me.

    Instead of:

    @dogs.sort: { .name }

    Something like:

    But even as already implemented, I agree it's an improvement and a nice language feature. Thanks, Patrick!

    • Part of the difference here is that .sort_by (or .sort) is a method call on the list as a whole, and any method call after that really ought to be treated as a method call on the resulting sorted list. For example,

      @list.sort.reverse { ... }

      Also, something like gets the invocant in the wrong place, because in order for this to work the invocants to .name should be the individual elements of @list.

      So, I think the information on how to sort (e.g., .name) really deserves to

  • Nice. Ever since I learnt Ruby I'm kind of envious that it has a .sort_by method whereas in Perl we have to do fleshed-out Schwartzian transform. This will make me feel at home again in Perl :-)
  • Turns out that this particular form of sort already exists in the Perl 6 spec -- it was just in an odd place. In Synopis 3, we have:

    The advantage of the method form is that it can be used in places that
    require tighter precedence than C<~~> provides:
        sort { $^a.M <=> $^b.M }, @files
    though that's a silly example since you could just write:
        sort { .M }, @files

    So, it's just Synopsis 29 that needs to be updated, and as of this morning Moritz++ has

  • 1: Why do you test if the arity 2: Do you really want to compare with cmp always? Your .say for %hash.sort: { .value.abs } example will no longer work if %hash has entries that are more then one digit. (Or did cmp change meaning between 5 and 6 to magically DWIM re numeric vs stringy compares -- I haven't been paying all that much attention for a long while now.)
    • Sorry for the rather fragmented first issue. It should say something along the lines of "why do you test if the airity is less then 2, rather then testing for it being exactly 1?"