Moving upward.
This commit is contained in:
parent
722e2f8782
commit
3236f7676e
8
nih.asd
8
nih.asd
|
@ -1,13 +1,15 @@
|
|||
(defsystem "nih"
|
||||
:version "0.1"
|
||||
:version "0.3"
|
||||
:author "Jaidyn Ann <jadedctrl@teknik.io>"
|
||||
: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")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)))
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
|
||||
|
|
Reference in New Issue