calc: Let Command
13.4 The Let Command
====================
If you have an expression like ‘a+b^2’ on the stack and you wish to
compute its value where ‘b=3’, you can simply store 3 in ‘b’ and then
press ‘=’ to reevaluate the formula. This has the side-effect of
leaving the stored value of 3 in ‘b’ for future operations.
The ‘s l’ (‘calc-let’) command evaluates a formula under a
_temporary_ assignment of a variable. It stores the value on the top of
the stack into the specified variable, then evaluates the second-to-top
stack entry, then restores the original value (or lack of one) in the
variable. Thus after ‘' a+b^2 <RET> 3 s l b <RET>’, the stack will
contain the formula ‘a + 9’. The subsequent command ‘5 s l a <RET>’
will replace this formula with the number 14. The variables ‘a’ and ‘b’
are not permanently affected in any way by these commands.
The value on the top of the stack may be an equation or assignment,
or a vector of equations or assignments, in which case the default will
be analogous to the case of ‘s t <RET>’. Storing Variables.
Also, you can answer the variable-name prompt with an equation or
assignment: ‘s l b=3 <RET>’ is the same as storing 3 on the stack and
typing ‘s l b <RET>’.
The ‘a b’ (‘calc-substitute’) command is another way to substitute a
variable with a value in a formula. It does an actual substitution
rather than temporarily assigning the variable and evaluating. For
example, letting ‘n=2’ in ‘f(n pi)’ with ‘a b’ will produce ‘f(2 pi)’,
whereas ‘s l’ would give ‘f(6.28)’ since the evaluation step will also
evaluate ‘pi’.