Step 1: Installation
Installation of lisp on aptitude based package manager (like Debian/ Ubuntu) can be achieved by the following command.
$ sudo apt-get install clispAlongside this its recommended to install the HTML version of the book Common Lisp the language, 2nd Edition by Guy L. Steele Jr.
$ sudo apt-get install cltlThe book is installed in the /usr/share/doc/cltl/clm/index.html.
Step 2: Testing LISP functionality
Soon after installation clisp can be tested for functionality. The following sequence of commands test the lisp environment.
To start clisp
$ clispTry out the lisp-expression to add 2 and 2 the result is in the second line.
[1]> (+ 2 2)Build on more complex lists. The following expression is lisp way of (1*2)+ 6.
4
[2]> (+ (* 1 2) 6)Now with the increase in comfort and confidence that lisp is installed and functional. Assigning values to variables is done via the following command
8
[3]> (setq a 10)For an extremely simple loop using the print command to print hello world five times.
10
[4]> (do ((x 1 (+ x 1))) ((> x 5)) (print "hello world"))Step 3: Doing something more than "hello world"
"hello world"
"hello world"
"hello world"
"hello world"
"hello world"
NIL
Having done with assignments and control structures. The next thing is procedures / functions. LISP supports functions via the keyword defun.
[5]> (defun increment (x) (+ x 1))The line 5 defines the function named increment which essentially has one argument and one line in which the argument is incremented by one. The line 6 calls the function increment with the argument passed as second member of the list.
INCREMENT
[6]> (increment 10)
11
The following code finds the square of a variable x.
(defun square(x) (x*x))Exploration of LISP on emacs is another really interesting topic which needs a dedicated post.
(setq x 10)
(square x)
No comments:
Post a Comment