Here is a function which returns true if the argument is a list of atoms:
(defun ISLAT (L)
(cond
((null L) T)
((atom (car L))(ISLAT (cdr L)))
(T F)
)))
====================================================
Here is a function to check if atom A is a member of list L:
(defun member (A LAT)
(cond
((null LAT) F)
((EQ (car LAT) A) T)
(T (member A (cdr LAT)))
)))
=========================================================
Here is a function to remove an atom from a list:
(defun rember (A LAT)
(cond
((null LAT) ())
((EQ (car LAT) A) (cdr LAT))
(T (cons (car LAT)(rember A (cdr LAT))))
)))
========================================================
A function to return a list of the first elements of each sublist in a list of lists:
(defun firsts(L)
(cond
((null L) ( )) (T (cons (car (car L)) (firsts (cdr L))))
)))
========================================================
A function to insert NEW after the element OLD in the list L:
(defun insertR (OLD NEW L)
(cond
((null L) ())
((EQ (car L) OLD) (cons NEW (cdr L)) )
(T (cons (car L) (insertR OLD NEW (cdr L))))
)))
=========================================================
A function to substitute first occurence of OLD for NEW in list L:
(defun substitute (OLD NEW L)
(cond
(null L)())
(EQ (car L) OLD) (cons NEW (cdr L)))
(T (cons (car L) (substitute OLD NEW (cdr L))))
)))
===================================================
An example of a Do-loop:
(defun dolength (L)
(do (M L (cdr M)) (sum 0 (sum++)))
((NULL M) sum)
))
OR
(defun dolength(L)
(do ((M L)(sum 0)
((NULL M) sum)
(setq M (cdr M))
Setq sum (1+sum))))
===============================================
Finding length of a list as a PROG program:
(defun proglength(L)
(prog ((sum 0))
again
(cond ((null L)(return sum)))
(setq sum (1+sum))
(setq L (cdr L))
(go again)))
================================================
A LIBRARY DATABASE
(defun add_book(bookref title author publisher)
(setf (get bookref 'title) title)
(setf (get bookref 'author) author)
(setf (get bookref 'publisher) publisher)
(setq library (cons bookref library))
bookref)
-------------------------
(defun retrieve_by (property value)
(setq result nil)
(do ((L library (cdr L)))
((NULL L) result)
(cond (EQ (get (car L) property) value) (cons (car L) result))))