Primarily technical blog on Lisp, .NET, C# development.

Thursday, May 13, 2010

Lisp style

Consider the following snippets of code:

(let ((probed-path)
(not-found t))
(dolist (registry-expression asdf:*central-registry*)
(when not-found
(setf probed-path (eval registry-expression)))
(when (probe-file (merge-pathnames "asd-library.asd" probed-path))
(setf not-found nil)))

(first (remove-if #'null
(mapcar #'(lambda (x)
(when (probe-file
(merge-pathnames "asd-library.asd" (eval x)))
(eval x)))

Both codes perform the same task. The first one is more like a procedural/imperative code in style than the more functional second one.

By the way, they return the path for a registered library. It is not very useful since ADSF provides the same thing easily with a single function call:

(asdf:system-relative-pathname :asd-library "")

But I like to get back to it as a reference of lisp styles.