-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Routines shift and pop on lists should allow an option to pop or shift multiple elements in one op #436
Comments
I'm hesitant about this because the functionality you want is very easily composed using xx: my @new = @old.pop xx $n FWIW I would not have reached for splice here, as I associate it more for what it can do regarding putting things into arrays rather than what it can do taking things out. But I have done the above with xx many times. We might be able to save a few cycles by making a dedicated pop($n), and I don't have strong objections to it beyond it feeling superfluous (which may be an argument easily deflated by TMTOWTDI). |
Note that |
I was not aware of that, thanks! But, as @lizmat said, .pop is similar to .chop, so there is that precedent. And my proposal seems more natural to me. (What would Larry say?)
Nor would I, but that was the easiest thing at hand. I had never needed it before, and it was the only thing suggested on IRC that took care of my immediate need. I rest my case on the beauty of TMTOWTDI (as opposed to the ugly Pythonic way). |
I think this is a low-risk change (API design wise). I for one would have guessed right what the meaning of the arg is. So my vote is: Why not? |
Before we get to a decision, we first need a fully specified proposal. We do not have that yet. We have an intriguing idea. What we still need is the rest of the design. Most notably, how would we treat edge cases like |
Other things to consider: Should Should Callables be allowed, as in Which should be the order in which multiple elements are to be returned? my @a = ^10;
dd @a.pop(2); # (8,9) or (9,8) ?? |
Currently it is awkward to accomplish that with routine splice. For example, to shift two elements into another list:
To pop two elements is even more awkward if you want the elements removed from the end as one would expect. The routine name is not intuitive, either.
It would be much easier, and intuitive, to do this:
or
The text was updated successfully, but these errors were encountered: