Skip to content

Instantly share code, notes, and snippets.

@lispm
Created December 9, 2012 13:15
Show Gist options
  • Save lispm/4244826 to your computer and use it in GitHub Desktop.
Save lispm/4244826 to your computer and use it in GitHub Desktop.
(defun find-query (query descriptions)
(find query descriptions
:test (lambda (q b)
(interpret-query q b))
:key #'second))
(defun lookup (v bindings)
(let ((result (assoc v bindings)))
(if result
(second result)
(error "variable ~a not known" v))))
(defun interpret-query (q bindings)
(cond ((numberp q) q)
((symbolp q) (lookup q bindings))
((consp q)
(destructuring-bind (op a b)
q
(case op
(and (and (interpret-query a bindings) (interpret-query b bindings)))
(or (or (interpret-query a bindings) (interpret-query b bindings)))
(> (> (interpret-query a bindings) (interpret-query b bindings)))
(< (< (interpret-query a bindings) (interpret-query b bindings)))
(= (= (interpret-query a bindings) (interpret-query b bindings))))))))
(defun test ()
(find-query '(and (> length 4) (< size 8))
'((a ((length 3) (size 5))) (b ((length 5) (size 7))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment