Section 6.11 The % Shortcut
Many of the exercises in the activities will involve executing multiple commands to obtain the answer. Often, this means running a command and then running a second command on the result of the first. Although copying and pasting the result from the first command takes less time than typing it out, it often causes many syntax problems.
Fortunately, Maple provides us with the
% shortcut, also called the ditto operator. Every time a command is run, its output is temporarily stored, much like a scientific calculator will remember what is currently on its screen. Using the % symbol within another command will use the result of the first command automatically.
The trouble with this shortcut comes from the fact that you can run Maple input anywhere on the page in any order! In the example below, you will only get the correct output if you run the second line immediately after running the first line.
> x^2 + 5;
\begin{equation*}
\displaystyle {x}^{2}+5
\end{equation*}
> sqrt(%);
\begin{equation*}
\displaystyle \sqrt{{x}^{2}+5}
\end{equation*}
To make better use of the % shotcut, it is the best practice to combine the two consecutive commands on the same Maple input:
Aside
> x^2 + 5; sqrt(%);
\begin{equation*}
\displaystyle {x}^{2}-4
\end{equation*}
\begin{equation*}
\displaystyle \sqrt{{x}^{2}+5}
\end{equation*}
