Skip to content

Instantly share code, notes, and snippets.

@making
Created December 16, 2009 18:38
Show Gist options
  • Save making/258051 to your computer and use it in GitHub Desktop.
Save making/258051 to your computer and use it in GitHub Desktop.
(defmacro config-value-bind ((fname &rest symbols) &body body)
(let ((s (gensym "s"))
(f (gensym "f"))
)
`(with-open-file (,f ,fname)
(let* ((,s (read ,f))
,@(mapcar #'(lambda (x) `(,x (cdr (assoc ',x ,s)))) symbols)
)
,@body
)
)
))
#|
;; == config.sexp ==
;; kokokara
((hoge . "xxx")
(foo . yyy)
(bar . :zzz)
)
;; kokomade
;; == how to use ==
(config-value-bind ("config.sexp"
hoge foo bar)
(list hoge foo bar)
) ; -> ("xxx" YYY :ZZZ)
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment