Beginner Lisp Programming



Lisp goes back to the 50s and was popular in the 80s. It is one of the oldest programming languages. According to Wikipedia, Fortran is the only high level programming language older than Lisp. There were many dialects back then, but Common Lisp is the dialect of our age. It has been called the programmable programming language. It has a very interesting history.

Check out this interview with LISP designer John McCarthy (1927-2011). He is interviewed about artificial intelligence by Jeffrey Mishlove in a Thinking Allowed production. On a side note, the Thinking Allowed series and Jeffrey Mishlove's interviews are a long time favorite of mine. I highly recommend watching some of the other videos they offer.

Below are some short code snippets to give you a taste of Common Lisp. All examples are written to run on GNU CLISP. Most common GNU/Linux distributions provide a clisp package. Run a program with

clisp myprog.lisp

Hello World

(write-line "Hello, world!") ; Semicolons are comments


(+ 5 7)
(- 15 5)
(* x x x) ; cube x


(setq x 10.5) ; Sets x to 10.5
(setq str "String variable")


(print 10)
(write-line "Write string to line")
(format t "Format text like printf ~d ~s ~%" 10 "string text") ;~% is like a \n


(loop for i from 0 to 10 by 2 do 
  (print i)

(loop while (<= x 10) do

(dotimes (x 10)
  (print x)


(defun sayhi()
  (write-line "Hi!")

(defun cube(x) ; define cube function
  (* x x x)
(cube 5) ; Call the cube function