2.2 Using FreeLisp
Note: If at any time you wish to end your session with FreeLisp, you can exit the environment as you would any other Windows application. Simply double click in the Control-menu box in the listener window, and click on 'Yes' in the dialog asking if you are sure
The 'FreeLisp' window contains a single pane showing the following piece of text in its top left-hand corner:
CL-USER 1 >This text is known as the prompt. Immediately to the right of the prompt is printed the cursor.
The prompt and cursor help you identify the point in the listener at which anything you type will be evaluated. The prompt also contains useful information, explained later.
To familiarize yourself with the listener, follow the instructions below, which form a short lesson.
1. Type the number 12
at the prompt, and press Return (or Enter).
Note: In future, assume that you should press Return (or Enter) after typing anything at the prompt.
The Common Lisp interpreter evaluates this input and prints the result of that evaluation. When the interpreter evaluates a number, the result is the number itself, and so 12
is printed out:
CL-USER 1 > 12 12 CL-USER 2 >When results are printed in the listener, they start on the line following the last line of input, that is, immediately below the point at which you pressed Return.
The 12
is printed immediately below the first prompt, and below that, another prompt is printed.
Note: Any Common Lisp form typed at the prompt is evaluated and its results printed immediately below in the listener.
Notice that the second piece of text in the prompt, each time a number, changes from 1 in the first prompt to 2 in the second. For now, consider that this represents the number of times the prompt has been printed. Later, you will find out how to use these numbers to help enter previously-typed forms again without typing them out in full.
The first piece of text names the current package.
Note: You are now ready to start work with Common Lisp using the FreeLisp environment. If you know nothing about the language, please read the introductory chapter or chapters of your Common Lisp tutorial before proceeding any further with this introduction.
From this point onward, it is assumed that you understand some of the basic elements and principles of Common Lisp.
2. Type *
at the current prompt
CL-USER 2 > * 12 CL-USER 3 >* always has as its value the result of the previous expression, in this case, 12, which was the result of the expression typed at the first prompt.
3. Type (setq val 12)
at the current prompt
CL-USER 3 > (setq val 12) 12 CL-USER 4 >The expression sets
val
to 12
. The result of evaluating the form is the value to which val
has been set: 12
, and thus the listener prints 12
below the form typed at the prompt.Note: In future, assume that you should type at the current prompt, that is, the one with the highest number. Later on, you will learn how to move the cursor to different places, thus you might not always be at the current prompt.
This is exactly the same behavior as before, when upon typing a number it was evaluated and the result printed in the listener. What is different this time, of course, is that the environment has been told to 'remember' that 12
is associated with val
4. Type val
CL-USER 4 > val 12 CL-USER 5 >The form is evaluated and
12
is printed below it.5. Type (+ val val val)
CL-USER 5 > (+ val val val) 36 CL-USER 6 >The form, which computes the sum of three
val
s, is evaluated, and 36
is printed below it.
If you change val
to some other number, and want to know the sum of three val
s again, you can avoid re-typing the form which computes it. To see how this is done, follow the instructions below.
6. Type (setq val 1)
CL-USER 6 > (setq val 1) 1 CL-USER 7 >The variable
val
is now set to 1.
In addition to typing Common Lisp forms in the listener, there are also a number of commands you can use. One of these is :redo
, which re-evaluates a specified form typed at an earlier prompt.
7. Type :redo 5
CL-USER 7 > :redo 5 (+ VAL VAL VAL) 3 CL-USER 8 >You must type the colon. The command instructs the environment to find the form typed at the prompt numbered
5
, and evaluate it again.
This time the form evaluates to the number 3
, because val
changed in the interim.
Notice that, before the 3
is printed, the form being re-evaluated is also printed. This is useful because it proves that the correct prompt number was selected.
The :redo
command provides a convenient means of re-entering complicated forms without having to type them out again. It can be used in other ways than that demonstrated. See Chapter 10, "The Listener".
The forms and commands typed at previous prompts are stored in what is called the history list of the listener. It is so named because it records the listener's 'history': all the forms and commands ever typed in it. The individual forms and commands in the history are known as events.
You can obtain a list of the last twenty events in the history by typing :his
at the prompt.
8. Type :his
CL-USER 8 > :his 1 : 12 2 : * 3 : (SETQ VAL 12) 4 : VAL 5 : (+ VAL VAL VAL)) 6 : (SETQ VAL 1) 7 : (+VAL VAL VAL)) CL-USER 8 >Each of the events in the listener so far are listed, because there are fewer than twenty. If there were more than twenty and you wanted to see them all, you could do so by supplying a number to the
:history
command. You can use a number smaller than twenty to constrain the number of events printed.
9. Type :his 3
CL-USER 8 > :his 3 5 : (+ VAL VAL VAL) 6 : (SETQ VAL 1) 7 : (+ VAL VAL VAL) CL-USER 8 >The environment lists the last three events in the history.
History information requests do not advance the history number of the prompt. They are not placed in the history list.
You can also select events from the last twenty in the history list from the History menu.
Sometimes the Listener may not respond as you would expect. If this happens, simply press Esc k
or choose Update from the Works menu.
Generated with Harlequin WebMaker