024d042b3147

Add `query-for`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 26 Sep 2016 12:28:06 +0000
parents 3383e2593fe2
children c9ecd6ef59b9
branches/tags (none)
files package.lisp src/ui.lisp

Changes

--- a/package.lisp	Sat Sep 24 17:33:22 2016 +0000
+++ b/package.lisp	Mon Sep 26 12:28:06 2016 +0000
@@ -82,6 +82,7 @@
     #:invoke-query
     #:invoke-query-all
     #:invoke-query-map
+    #:invoke-query-for
     #:invoke-query-do
     #:invoke-query-find
     #:invoke-prove
@@ -89,6 +90,7 @@
     #:query
     #:query-all
     #:query-map
+    #:query-for
     #:query-do
     #:query-find
     #:prove
--- a/src/ui.lisp	Sat Sep 24 17:33:22 2016 +0000
+++ b/src/ui.lisp	Mon Sep 26 12:28:06 2016 +0000
@@ -140,6 +140,13 @@
               nil))
     (nreverse results)))
 
+(define-invocation (invoke-query-for invoke-query-for-aot) (variable)
+  (let ((results nil))
+    (invoke (lambda (result)
+              (push (getf result variable) results)
+              nil))
+    (nreverse results)))
+
 (define-invocation (invoke-query-do invoke-query-do-aot) (function)
   (invoke (lambda (result)
             (funcall function result)
@@ -178,6 +185,9 @@
 (defmacro query-map (database function &rest terms)
   `(invoke-query-map ,database ,function ,@(quote-terms terms)))
 
+(defmacro query-for (database variable &rest terms)
+  `(invoke-query-for ,database ',variable ,@(quote-terms terms)))
+
 (defmacro query-do (database function &rest terms)
   `(invoke-query-do ,database ,function ,@(quote-terms terms)))
 
@@ -219,6 +229,8 @@
 
 (define-invocation-compiler-macro invoke-query-map invoke-query-map-aot (database function))
 
+(define-invocation-compiler-macro invoke-query-for invoke-query-for-aot (database variable))
+
 (define-invocation-compiler-macro invoke-query-do invoke-query-do-aot (database function))
 
 (define-invocation-compiler-macro invoke-query-find invoke-query-find-aot (database predicate))