diff --git a/LICENSE b/LICENSE index 3ae444c..65ba448 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2023 Anders Hoff +Copyright (c) 2023-2024 Anders Hoff Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/lqn.md b/docs/lqn.md index ab4e5fe..e748790 100644 --- a/docs/lqn.md +++ b/docs/lqn.md @@ -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: diff --git a/src/init.lisp b/src/init.lisp index 2c814be..daf2f7d 100644 --- a/src/init.lisp +++ b/src/init.lisp @@ -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 diff --git a/src/io.lisp b/src/io.lisp index 449e089..83c7974 100644 --- a/src/io.lisp +++ b/src/io.lisp @@ -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))) diff --git a/src/packages.lisp b/src/packages.lisp index 1ca9392..b3c7149 100644 --- a/src/packages.lisp +++ b/src/packages.lisp @@ -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? diff --git a/src/qry-operators.lisp b/src/qry-operators.lisp index dae9800..f885260 100755 --- a/src/qry-operators.lisp +++ b/src/qry-operators.lisp @@ -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 @@ -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 @@ -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)))) @@ -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)))))) diff --git a/src/qry-utils.lisp b/src/qry-utils.lisp index 5b1f8ff..871a8ea 100644 --- a/src/qry-utils.lisp +++ b/src/qry-utils.lisp @@ -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*) @@ -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)) diff --git a/test/test-lqn-2.lisp b/test/test-lqn-2.lisp index f98f1a5..880d01a 100644 --- a/test/test-lqn-2.lisp +++ b/test/test-lqn-2.lisp @@ -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) @@ -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)