Up | Next | Prev | PrevTail | Tail |
It is often useful to be able to reference results of previous computations during a REDUCE session; see also 8.2. For this purpose, REDUCE maintains a history of all interactive inputs and the results of all interactive computations during a given session. These results are referenced by the command number that REDUCE prints automatically in interactive mode. To use a previous input expression in a new computation, write input(\(n\)), where \(n\) is the command number. To use a previous output expression, write ws(\(n\)) (where WS stands for WorkSpace). ws used as a variable (rather than a function) references the previous output expression. For example:
1: int(x-1, x); x*(x - 2) ----------- 2
\(\vdots \)
7: (x^2-1)/(x+1); x - 1
\(\vdots \)
15: 2*input(1)-ws(7)^2; -1 16: 2*ws(1)-ws(7)^2; -1 17: x := 101; x := 101 18: ws(7); 100
Inputs 15 and 16 above yield the same result, but input 16 does so without recomputing the integral. However, an output expression referenced using ws is re-evaluated in the current context, as shown by the last two statements above.
Note that input that causes an error, and some commands such as let statements, file handling and mode changing, do not produce an output expression, so the output from such input cannot be accessed. ws used as a variable returns the last output expression, which does not necessarily correspond to the last input, and ws used as a function reports an error if you try to access non-existent output. For example:
1: 6*7; 42 2: 0/0; ***** 0/0 formed 3: ws; 42 4: ws 2; ***** Entry 2 not found 5: let x => 0; 6: ws; 42 7: ws 5; ***** Entry 5 not found
The operator display is available to display previous inputs. If its argument is a positive integer, \(n\) say, then the previous \(n\) inputs are displayed. If its argument is all (or in fact any non-numerical expression), then all previous inputs are displayed.
Up | Next | Prev | PrevTail | Front |