aboutsummaryrefslogtreecommitdiff
path: root/src/util.lisp
blob: 2fc079b08ed586dfb647b2bc6f0b5e096894ea89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
;;;; util.lisp -- some utilities 

(in-package :oneliners.api)

(defun plist-find (indicator plist &key (test 'eq) (key 'identity))
  (loop for (ind val . more) on plist by #'cddr
        when (funcall test indicator (funcall key ind))
          return val))

(defmacro with-plist ((&rest keys) plist &rest body)
  (let ((the-plist (gensym)))
    `(let ((,the-plist ,plist))
       (let
           ,(loop for key in keys
                  collect `(,key (plist-find (symbol-name ',key)
                                             ,the-plist
                                             :test #'string-equal
                                             :key #'symbol-name)))
         ,@body))))