Skip to content

Commit

Permalink
rename @@ to @get
Browse files Browse the repository at this point in the history
  • Loading branch information
inconvergent committed May 21, 2024
1 parent 80e5ee3 commit 691cda8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docs/lqn.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
```

```
; LQN:@@
; LQN:@GET
; [symbol]
;
; @@ names a compiled function:
; @GET names a compiled function:
; Lambda-list: (A PATH &OPTIONAL D)
; Derived type: (FUNCTION (T T &OPTIONAL T) *)
; Documentation:
Expand Down
2 changes: 1 addition & 1 deletion src/init.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(defvar *opt* '(optimize (speed 3) (safety 1)))
(defvar *fxns* '(:err :wrn :nope :noop :lst :lit :qt :hld :ghv :pnum :inum :cnt
:fmt :out :jsnstr
:fn :fi :ctx :par :itr :key :val :compct :?? :@@ :@*
:fn :fi :ctx :par :itr :key :val :compct :?? :@get :@*
:read? :some? :all? :none? :smth? :size?
:new* :new$ :cat* :cat$
:ind* :sel :seq :apply* :grp :uniq
Expand Down
2 changes: 1 addition & 1 deletion src/io.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ as alists. see ldnload."
0.7332 0.7602 0.7834 0.8037 0.9999)))
(loop with s = (clmp s) for i from 0 for v across dens
if (>= v s) do (return-from ascii (aref chars i)))
(@@ chars -1 nil)))
(@get chars -1 nil)))

2 changes: 1 addition & 1 deletion src/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(:nicknames #:cl-lqn)
(:export #:d? #:v?
#:qry #:qrydb #:qryd #:jsnqryf #:qryl #:proc-qry
#:jsnloads #:jsnloadf #:jsnout #:ldnout #:ldnload #:fmt #:out #:jsnstr #:@* #:@@ #:??
#:jsnloads #:jsnloadf #:jsnout #:ldnout #:ldnload #:fmt #:out #:jsnstr #:@* #:@get #:??
#:read? #:some? #:none? #:all? #:empty? #:size? #:is?
#:path? #:subdir #:subfiles #:ls #:dir? #:file? #:cwd #:now #:cmd
#:some? #:all? #:none? #:cd #:keys?
Expand Down
14 changes: 7 additions & 7 deletions src/qry-operators.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
,∇-))))

(defun compile/@ (rec conf d &aux (dat (gk conf :dat)))
(case (length d) (0 `(@@ ,dat 0 nil))
(1 `(@@ ,dat ,(funcall rec conf (car d))))
(2 `(@@ ,dat ,@(funcall rec conf d)))
(3 `(@@ ,@(funcall rec conf d)))
(case (length d) (0 `(@get ,dat 0 nil))
(1 `(@get ,dat ,(funcall rec conf (car d))))
(2 `(@get ,dat ,@(funcall rec conf d)))
(3 `(@get ,@(funcall rec conf d)))
(otherwise (error "@: expected 0-3 arguments. got:~%~a." d))))

(defun compile/?map (rec conf d) ; #(...) ; do this sequence of expressions on each item
Expand Down Expand Up @@ -111,7 +111,7 @@
(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)))
collect `(let ((,dat (@get ,par ,kk)))
(declare (ignorable ,dat))
(██∈ (:key ,kk)
,(compile/$add rec
Expand All @@ -131,7 +131,7 @@
for ,kvres of-type hash-table = ,(if (car- dat? d) `(make$ ,itr) `(new$))
do (██∈ (:par ,par :cnt ,i :itr ,itr)
,@(loop for (m kk expr) in (strip-all d)
collect `(let ((,dat (@@ ,itr ,kk)))
collect `(let ((,dat (@get ,itr ,kk)))
(declare (ignorable ,dat))
(██∈ (:key ,kk) ,(compile/$add rec
(dat/new conf dat) m kvres kk expr))))
Expand All @@ -155,7 +155,7 @@
do (██∈ (:par ,par :cnt ,i :itr ,itr)
,(when (car- dat? d) (compile/*add rec conf :+ vres itr))
,@(loop for (m kk expr) in (strip-all d) collect
`(let ((,dat (@@ ,itr ,kk)))
`(let ((,dat (@get ,itr ,kk)))
(declare (ignorable ,dat))
(██∈ (:key ,kk) ,(compile/*add rec
(dat/new conf dat) m vres expr))))))
Expand Down
10 changes: 5 additions & 5 deletions src/qry-utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ match. If b is an expression, a is compared to the evaluated value of b."
"evaluate expr only if a is not nil. returns the result of expr or res; or nil."
`(and ,a ,expr ,@(if res `(,res))))

(defun @@ (a path &optional d) (declare #.*opt*)
(defun @get (a path &optional d) (declare #.*opt*)
"get nested key (e.g. aa/2/bb) from nested structure of kv/vec"
(labels ((err (p) (error "@@: unexpected path: ~a" p))
(wrn (p) (warn "@@: unexpected path: ~a" p))
(labels ((err (p) (error "@get: unexpected path: ~a" p))
(wrn (p) (warn "@get: unexpected path: ~a" p))
(gkv (a* k) (typecase a* (hash-table (gethash k a*)) (otherwise nil)))
(ind (a* k) (if (< k 0) (+ (length a*) k) k))
(gv (a* k) (when (vec? a*)
Expand Down Expand Up @@ -148,10 +148,10 @@ match. If b is an expression, a is compared to the evaluated value of b."
(otherwise o*))))
(rec o)))

(defun @* (a d &rest rest &aux l) (declare #.*opt*) ; TODO: use @@ for all
(defun @* (a d &rest rest &aux l) (declare #.*opt*) ; TODO: use @get for all
"pick these indices/keys from sequence/hash-table into new vector."
(labels ((lt (l) (or (nth l a) d))
(kv (k) (@@ a k d))
(kv (k) (@get a k d))
(gt (i) (if (< i l) (aref a i) d)))
(typecase a (vector (setf l (length a)) (map 'vector #'gt rest))
(hash-table (map 'vector #'kv rest))
Expand Down
4 changes: 2 additions & 2 deletions test/test-lqn-2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

(is (lqn:uniq (lqn:new* 5 1 1 1 2 3 3 4 5)) #(1 2 3 4 5) :test #'equalp))

(subtest "lqn qry @@/@"
(subtest "lqn qry @get/@"
(is (lqn:qryd (lqn:jsnloads "{\"a\": {\"b\": 3, \"c\": 7}}") (|| (@ "a") (@ "b"))) 3)
(is (lqn:qryd (lqn:jsnloads "{\"a\": {\"b\": 3, \"c\": 7}}") (|| (@ "a") (@ "b"))) 3)
(is (lqn:qryd (lqn:jsnloads "{\"a\": {\"b\": 3, \"c\": 7}}") (|| (@ :a) (@ :b))) 3)
Expand Down Expand Up @@ -161,7 +161,7 @@
(|| #[:things] (flatn* _) #((cat$ {:id} {:?@extra})))))
#(((:ID . 0) (:EXTRA . "extra99")) ((:ID . 10) (:EXTRA . "extra1"))
((:ID . 11) (:EXTRA . "extra2")) ((:ID . 12)) ((:ID . 31)) ((:ID . 32))) :test #'equalp)
(is-str (lqn::jsnstr (lqn:jsnqryf *test-data-fn* (|| (@@ _ "*/things/*/extra"))))
(is-str (lqn::jsnstr (lqn:jsnqryf *test-data-fn* (|| (@get _ "*/things/*/extra"))))
"[[\"extra99\"],[\"extra1\",\"extra2\"]]")

(is (lqn:qry "1 x 1 x 7 x 100" (splt _ :x) int!? (?fld 0 +)) 109)
Expand Down

0 comments on commit 691cda8

Please sign in to comment.