Skip to content

Instantly share code, notes, and snippets.

@pkhuong
Last active December 18, 2015 10:10
Show Gist options
  • Save pkhuong/5766855 to your computer and use it in GitHub Desktop.
Save pkhuong/5766855 to your computer and use it in GitHub Desktop.
(defun foo (&rest arguments)
;; this should all be gensymmed
(let (a-value a-p b-value b-p allow-other-keys allow-other-keys-p other-key-p)
(loop while arguments do
(let ((key (pop arguments))
(value (if (null arguments)
(error "Odd number of keyword arguments")
(pop arguments))))
(case key
(:a
(unless a-p
(setf a-value value
a-p t)))
(:b
(unless b-p
(setf b-value value
b-p t)))
(:allow-other-keys
(unless allow-other-keys-p
(setf allow-other-keys value
allow-other-keys-p t)))
(t
(setf other-key-p t)))))
(when (and other-key-p
(not allow-other-keys))
(error "Unknown keyword argument(s)"))
(let* ((a (if a-p
a-value
(a-default-form)))
(b (if b-p b-value b-default-form)))
...)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment