Lisp Reference
They say that once you try Lisp, you will never be the same again. I highly recommend checking it out even if you are not planning to use it. It is interesting experience, as Lisp requires much more different thinking than most of the modern languages.
Bare Bone Basics:
; this is a lisp comment (function argument argument ... argument)
More to come…
Here are few simple programs in lisp (clisp actually) that I found on my hard drive.
Fibonacci Series:
(defun fib (n) (cond ((= n 0) 0) ((= n 1) 1) ((+ (fib (- n 1)) (fib (- n 2)))) ) )
Count Occurrences
Counts all occurrences of an element in a list.
(cnt ‘pear ‘(apple pear pear peach))
(defun cnt (target mylist) (if (null mylist) 0 (if (equal target (first mylist)) (+ 1 (cnt target (rest mylist))) (+ 0 (cnt target (rest mylist))) ) ) )
This one recurses into sublists (using cnt function):
(cntAll ‘apple ‘(apple (apple pear) plum))
(defun cntAll (target mylist) (if (null mylist) 0 (if (listp (first mylist)) (+ (cnt target (first mylist)) (cntAll target (rest mylist)) ) (if (equal target (first mylist)) (+ 1 (cntAll target (rest mylist))) (+ 0 (cntAll target (rest mylist))) ) ) ) )
Insertion Sort
Takes in a list of integers, eg: (insertSort ‘(5 3 2 6 7 9 11))
(defun insert (num mylist) (if (null mylist) (cons num '()) (if (< num (first mylist)) (cons num mylist) (cons (first mylist) (insert num (rest mylist))) ) ) ) (defun insertSort (mylist) (if (null mylist) NIL (insert (first mylist) (insertSort (rest mylist))) ) )

