Clojure Distilled 12 years ago
Extracting keys from maps into a definition, with common-lisp (using my macro defk)
(defk login (user pass) (and (string= user "Bob") (string= pass "secret")))
(login (list-to-hash '(user "Bob" pass "secret")) (list-to-hash '(user "Bob" pass "secret"))
Given the following definitions:
(defmacro defk(name h-list &rest body) `(defun ,name (h) (let ,h-list ,@(loop for k in h-list collect `(setq ,k (gethash (quote ,k) h))) ,@body)))
(defun list-to-hash(list) (let ((h (make-hash-table))) (loop for (k v) on list by #'cddr do (setf (gethash k h) v)) h))