diff --git a/nih.asd b/nih.asd index b54b2af..006b81e 100755 --- a/nih.asd +++ b/nih.asd @@ -1,13 +1,15 @@ (defsystem "nih" - :version "0.1" + :version "0.3" :author "Jaidyn Ann " - :license "CC 0" - :depends-on ("cl-strings" "cl-ppcre") + :license "LGPLv3" + :depends-on ("cl-strings" "asdf-encodings" "cl-ppcre") :components ((:module "src" :components ((:file "package") (:file "misc") + (:file "file") (:file "list") + (:file "date") (:file "string/string") (:file "string/word") (:file "string/line") diff --git a/src/package.lisp b/src/package.lisp index c9df757..01555d8 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -27,6 +27,11 @@ :getf-string :getf-strings + :getf-car + :getf-cars + :getf-cadr + :getf-cadrs + :get-colon-values :remove-colon-values :replace-colon-value diff --git a/src/string/string.lisp b/src/string/string.lisp index 44e3e2d..42f95c6 100644 --- a/src/string/string.lisp +++ b/src/string/string.lisp @@ -272,6 +272,60 @@ Example: stack)) +;; LIST_OF_SUBLISTS STRING --> LIST_OF_SUBLISTS_WITH_STRING_AS_CAR +(defun getf-cars (list value &key (stack '()) (test 'eq)) + "Get items from list by an identifying string in `car`. + I.E., if the string is 'apple', any sublists like this: + ('apple' 1 2 3) + will be returned." + + ;; just recurse through the list, adding each new matching + ;; item to the `stack` + + (if (and (< 0 (length list)) (listp list)) + (if (ignore-errors + ;; the item might not be a list; for our purposes, let's ignore that. + (funcall test + (car (car list)) ;; '( ( here ) ) + value)) + (getf-cars (cdr list) value + :test test + :stack (concatenate 'list stack (list (car list)))) + (getf-cars (cdr list) value + :stack stack + :test test)) + stack)) + +(defun getf-car (list value &key (test 'eq)) + (car (getf-cars list value :test test))) + +;; LIST_OF_SUBLISTS STRING --> LIST_OF_SUBLISTS_WITH_STRING_AS_CAR +(defun getf-cadrs (list value &key (stack '()) (test 'eq)) + "Get items from list by an identifying string in `car`. + I.E., if the string is 'apple', any sublists like this: + ('apple' 1 2 3) + will be returned." + + ;; just recurse through the list, adding each new matching + ;; item to the `stack` + + (if (and (< 0 (length list)) (listp list)) + (if (ignore-errors + ;; the item might not be a list; for our purposes, let's ignore that. + (funcall test + (cadr (car list)) ;; '( ( here ) ) + value)) + (getf-cadrs (cdr list) value + :test test + :stack (concatenate 'list stack (list (car list)))) + (getf-cadrs (cdr list) value + :stack stack + :test test)) + stack)) + +(defun getf-cadr (list value &key (test 'eq)) + (car (getf-cadrs list value :test test))) + ;; ----------------------------------------