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.
  • 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 be an argument to the sort method, as opposed to a method itself.

      I did think of using the method name .sort_by as a way of distinguishing the "sort by comparison function" from the "sort by value" behavior, but I think/hope the dwimminess of using the block to determine that is sufficient. It's much nicer to always think "sort" than to have to wonder or remember the answer to "do I need '.sort' here or '.sort_by'?"

      Of course, Larry and the folks on perl6-language get the strongest vote, and I'll be glad to implement whatever API they finally decide on.