Last active
December 18, 2015 10:10
-
-
Save pkhuong/5766855 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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