In dc, how do I pop and discard a number from the top of the stack? A stack with three items (1 2 3
) should become a stack with two items (2 3
). Currently I'm shoving the number onto another stack (Sz) but that seems rather lame.
There are numerous ways to delete the top of the stack but they have side effects. Removing an element without side effects requires you to avoid included side effects.
To remove the top of the stack without a side effect, ensure that the top is a number and then run d!=z
. If the stack had [5], this does the following
Stack: [5]
Stack: [5,5]
5 != 5
Stack: []
z
Stack: []
To ensure that the top of stack is a number, I use Z
which will calculate the length of a string or the number of digits in a number and push that back. There are other options such as X. Anything that makes a number out of anything will work so that it will be compatible with !=.
So the full answer for copy pasting in all situations is the following:
Zd!=r
I usually stick this in register D (for Drop):
[Zd!=r]sD
and then I can run
lDx