Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
inconvergent committed May 15, 2024
1 parent 48b1190 commit 257594d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/qry-operators.lisp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(in-package :lqn)

(defmacro o∈ (s ∇ expr) (declare (ignore s)) `(setf ,,expr))
(defun opstr (op &optional (fx #'car)) (sdwn (head (str! (funcall fx op)) 50)))
(defmacro o∈ (∇ s expr) (declare (ignore s)) `(setf ,,expr))
(defun compile/|| (rec conf d) ; (|| ...) pipe
(awg (∇-)
(if (< (length d) 2) (funcall rec conf (car d))
`(let ((,∇- ,(gk conf :dat)))
,@(loop for op in d
collect `(o∈ ,(sdwn (head (str! op) 50)) ,∇-
collect `(o∈ ,∇- ,(opstr op)
,(funcall rec (dat/new conf ∇-) op)))
,∇-))))

Expand All @@ -24,14 +25,14 @@
(labels ((do-map ()
`(let ((,par ,(gk conf :dat)))
(labels
((map-do-ht ()
((map-do-ht () ,(opstr d)
(loop with ,kres = (new$) for ,i from 0
for ,itr being the hash-values of ,par using (hash-key ,k)
do (∈ (:par ,par :cnt ,i :itr ,itr :key ,k)
(setf (gethash ,k ,kres)
,expr))
finally (return ,kres)))
(map-do-vec ()
(map-do-vec () ,(opstr d)
(loop with ,vres = (mav) with ,par = (vec! ,par) for ,i from 0
for ,itr across ,par
do (∈ (:par ,par :cnt ,i :itr ,itr :key ,i)
Expand All @@ -52,12 +53,12 @@
(error "?fld: expected symbols, got: ~a/~a." acc itr))
(unless (consp expr) (error "?fld: expected cons or got: ~a." expr))
`(let ((,par ,(gk conf :dat)) (,acc ,init))
(labels ((fld-do-ht ()
(labels ((fld-do-ht () ,(opstr d)
(loop for ,i from 0
for ,itr being the hash-values of ,par using (hash-key ,k)
do (∈ (:par ,par :cnt ,i :key ,k :itr ,itr)
(setf ,acc ,(funcall rec (dat/new conf itr) expr)))))
(fld-do-vec ()
(fld-do-vec () ,(opstr d)
(loop with ,par = (vec! ,par)
for ,itr across ,par for ,i from 0
do (∈ (:par ,par :cnt ,i :key ,i :itr ,itr)
Expand All @@ -83,14 +84,14 @@
(do-key (cd) (funcall rec (dat/new conf itr)
(typecase cd (keyword `(@ ,cd)) (string `(@ ,cd)) (otherwise cd)))))
`(let ((,par ,(gk conf :dat)) (,kvres (new$)))
(labels ((grp-do-vec ()
(labels ((grp-do-vec () ,(opstr d)
(loop with ,par = (vec! ,par)
for ,i from 0 for ,itr across ,par
for ,key = (∈ (:par ,par :key ,i :cnt ,i) ,(do-key (car d)))
for ,acc = (gethash ,key ,kvres (new*))
do (∈ (:par ,par :cnt ,i :itr ,itr :key ,key)
(setf (gethash ,key ,kvres) (psh* ,acc ,(do-dat))))))
(grp-do-ht ()
(grp-do-ht () ,(opstr d)
(loop for ,i from 0
for ,itr being the hash-values of ,par using (hash-key ,k)
for ,key = (∈ (:par ,par :key ,k :cnt ,i) ,(do-key (car d)))
Expand All @@ -110,7 +111,7 @@
(defun compile/?select (rec conf d) ; {...} ; sel ; select keys/exprs from ht to new ht
(awg (kres par dat)
`(let* ((,par ,(gk conf :dat)))
(labels ((select-do-ht (&aux (,kres ,(if (car- dat? d) `(make$ ,par) `(new$))))
(labels ((select-do-ht (&aux (,kres ,(if (car- dat? d) `(make$ ,par) `(new$)))) ,(opstr d)
(∈ (:par ,par)
,@(loop for (m kk expr) in (strip-all d)
collect `(let ((,dat (@@ ,par ,kk)))
Expand All @@ -130,7 +131,7 @@
(defun compile/*$ (rec conf d) ; #{...} ; sel ; select from vec of hts to vec of hts
(awg (i vres kvres itr dat par)
`(let ((,par ,(gk conf :dat)))
(labels ((mapsel-do-vec (&aux (,vres (mav)))
(labels ((mapsel-do-vec (&aux (,vres (mav))) ,(opstr d)
(loop with ,par of-type vector = (vec! ,par)
for ,itr of-type hash-table across ,par for ,i from 0
for ,kvres of-type hash-table = ,(if (car- dat? d) `(make$ ,itr) `(new$))
Expand All @@ -154,7 +155,7 @@
(defun compile/$* (rec conf d) ; #[...] ; sel ; select from vec of hts to vec
(awg (i vres itr dat par)
`(let ((,par ,(gk conf :dat)))
(labels ((sel-do-vec (&aux (,vres (mav)))
(labels ((sel-do-vec (&aux (,vres (mav))) ,(opstr d)
(loop with ,par of-type vector = (vec! ,par)
for ,itr across ,par for ,i from 0
do (∈ (:par ,par :cnt ,i :itr ,itr)
Expand Down Expand Up @@ -182,15 +183,15 @@
(awg (k i kres vres itr par)
`(let ((,par ,(gk conf :dat)))
(labels
((filter-do-vec ()
((filter-do-vec () ,(opstr d)
(loop with ,par = (vec! ,par) with ,vres of-type vector = (mav) for ,i from 0
for ,itr across ,par
do ,(compile/?xpr rec
`((:par . ,par) (:dat . ,itr) (:cnt . ,i) (:itr . ,itr) (:key . ,i))
`(,@d (vex ,vres ,@(or (xpr/get-modes d :%) `(,itr)))
nil))
finally (return ,vres)))
(filter-do-ht ()
(filter-do-ht () ,(opstr d)
(loop with ,kres of-type hash-table = (new$) for ,i from 0
for ,itr being the hash-values of ,par using (hash-key ,k)
do ,(compile/?xpr rec
Expand Down

0 comments on commit 257594d

Please sign in to comment.