LISP is derived from the term LISt Processing.
A list in LISP looks like this:
(Knife Fork Spoon)
or like these two examples
(set-background-color "yellow") <- C-x C-e
(set-background-color "white") <- C-x C-e
If the first item in the list is a function you can evaluate the list by placing the cursor just after the bracket at the end of the list and pressing C-x C-e. Try it with the two lists above. Copy them into Emacs and then C-x C-e where indicated to turn the Emacs background yellow and then to set it white again.
If you try to evaluate the (Knife Fork Spoon) list you’ll get an error telling you that Knife is a void function.
Try evaluating the following lists in Emacs by typing C-x C-e after the closing bracket:
(linum-mode)
(message "This is the echo area")
(* 2 3)
(+ 4 5)
The last three will output their results in the echo area, the area at the bottom of Emacs.
You can also evaluate a function by typing M-x (function name)
. So M-x visual-line-mode
will turn word wrap on and off.
Emacs supports TAB completion, so typing M-x visu
and pressing TAB is enough to fill in the function name.
You set a variable as follows:
(set 'name 'John)
C-x C-e
to set the variable
name
C-x C-e
to see the contents of the variable “name”
If you press C-x C-e
after (name)
you’ll get an error. Remember, name
is a variable, (name)
is a function, and you haven’t defined a function called name.
It’s a nuisance typing in ‘ all the time, so the following is often used
(setq animal 'cat)
Evaluate the above and then evaluate animal …
C-u C-x C-e
will insert any output directly in the text area, rather than in the echo area.
Here is a list of cheeses called cheese:
(setq cheese '(Stilton Wensleydale Cheddar Cheshire))
Evaluate the list.
The first item in a list is called the car, the remaining items are called the cdr (pronounced could-er) The Emacs Lisp tutorial will tell you why. Evaluate the following:
(car cheese)
(cdr cheese)
… and there you are
Next: Functions in Elisp