There are many ways to remove the top of the stack, but they have side effects. Removing an item without side effects requires that you not include side effects.
To remove the top of the stack without a side effect, make sure the top number is a number, and then run d!=z If there was [5] on the stack, this does the following
- Start with the item to delete.
Stack: [5] - Duplicate the top of the stack.
Stack: [5,5] - Press top 2 and check if they are equal:
5 != 5 Stack: [] - If the test passes (which it cannot), run
z Stack: []
To make sure the top of the stack is a number, I use z , which will calculate the length of the string or the number of digits in the number and push it back. There are other options, such as X. Everything that makes a number out of anything will work so that it is compatible with! =.
Thus, the complete answer for inserting copies in all situations:
Zd!=r
I usually put this in the D register (for Drop):
[Zd!=r]sD
and then I can run
lDx
source share