I've started studying Lisp 2 days ago and I'm reading Paul Graham's ANSI Common List, which exposes the language structure in a very interesting way. It's not too much theoretical for beginners, and not too shallow (as Sierra-Bate's Head First Java, which personally I hate). After a brief general language introduction, he starts talking bout lists and raise an example of simple list compression. Basically, let el be an element which is repeated n times. You replace all of them by a single (n el) list. To do this he gave an code implementation, but I tried to do my own, which apparently is working. I'd like if possible, that someone analyses my code and show me the critical points of its implementation, which I'm sure there is a lot, since it's my first contact with Lisp. Thank u all!
(defun compress (x)
"compress a list replacing repeated sequential values for (<n> <value>)"
(let ((lst '()) (fst t) (lt nil) (n 0))
(dolist (el x)
(if fst
(progn
(setq fst nil)
(setq lt el)
(setq n 1))
(progn
(if (equal el lt)
(setq n (+ n 1))
(progn
(setq lst (cons (if (= n 1)
lt
(list n lt))
lst))
(setq lt el)
(setq n 1)
)))))
(setq lst (cons (if (and (not (= n 0)) (= n 1))
lt
(list n lt))
lst))
(reverse lst)))