5.4 Keep Arguments

The K (calc-keep-args) command acts like a prefix for the following command. It prevents that command from removing its arguments from the stack. For example, after 2 RET 3 +, the stack contains the sole number 5, but after 2 RET 3 K +, the stack contains the arguments and the result: ‘2 3 5’.

With the exception of keyboard macros, this works for all commands that take arguments off the stack. (To avoid potentially unpleasant behavior, a K prefix before a keyboard macro will be ignored. A K prefix called within the keyboard macro will still take effect.) As another example, K a s simplifies a formula, pushing the simplified version of the formula onto the stack after the original formula (rather than replacing the original formula). Note that you could get the same effect by typing RET a s, copying the formula and then simplifying the copy. One difference is that for a very large formula the time taken to format the intermediate copy in RET a s could be noticeable; K a s would avoid this extra work.

Even stack manipulation commands are affected. TAB works by popping two values and pushing them back in the opposite order, so 2 RET 3 K TAB produces ‘2 3 3 2’.

A few Calc commands provide other ways of doing the same thing. For example, ' sin($) replaces the number on the stack with its sine using algebraic entry; to push the sine and keep the original argument you could use either ' sin($1) or K ' sin($). See Algebraic Entry. Also, the s s command is effectively the same as K s t. See Storing Variables.

If you execute a command and then decide you really wanted to keep the argument, you can press M-RET (calc-last-args). This command pushes the last arguments that were popped by any command onto the stack. Note that the order of things on the stack will be different than with K: 2 RET 3 + M-RET leaves ‘5 2 3’ on the stack instead of ‘2 3 5’. See Undoing Mistakes.