« Template changes | Main | Cabin fever and the long haul »

Today in elisp

Noodling around, I went from



(defun keys (al)

  "return a list of the keys of an alist"

  (let (r '())

    (if (eq nil (cdr al))

	(list (car (car al)))

      (setq r (nconc (list (car (car al))) (keys (cdr al))))

      )))



(keys '((foo . bar) (bar . foo) (jumpin . jiminy) (holy . moly)))

(foo bar jumpin holy)

to


;; or, far more simply:

(defun keys (al)

  "return a list of the keys of an alist"

  (mapcar (lambda (l) (car l)) al))



(keys '((foo . bar) (bar . foo) (jumpin . jiminy) (holy . moly)))

(foo bar jumpin holy)

Yeesh.