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
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
__ (Score:1)
Now, what really would be cool is the return an iterator, returning the elements of the list in sorted order. The function wouldn't be called again until the list was exhausted. Example:
Reply to This
Re:__ (Score:2)
The other way to look at that is "I want my functions to behave insensibly in scalar context unless I remember to make it so" which strikes me as a little peevish and definately not DWIM.
That aside, here's something more concrete--how do you do that? Take this sample for example, which is much like the code I recently stumbled over...
return sort { $a cmp $b }
Re:__ (Score:1)
That sounds like for all functions that I design to return a list, I should take the trouble of figuring out what it they should do in list context.
Sorry, but I pass. For functions where it makes sense, I do so. But for many, I won't. Consider the context to be a pre-condition - just like the arguments being passed in.
Re: (Score:1)
That would require of Perl to do extra magic when it encounters
return sort, and it’s non-reentrant. I vote no. If you want an iterator, then an iterator object/closure should be returned. Let’s not create more instances of theeachtrap.