Browse code

Moving upward.

Jaidyn Lev authored on 2018-12-03 01:26:31
Showing 3 changed files
... ...
@@ -1,13 +1,15 @@
1 1
 (defsystem "nih"
2
-	   :version "0.1"
2
+	   :version "0.3"
3 3
 	   :author "Jaidyn Ann <jadedctrl@teknik.io>"
4
-           :license "CC 0"
5
-	   :depends-on ("cl-strings" "cl-ppcre")
4
+           :license "LGPLv3"
5
+	   :depends-on ("cl-strings" "asdf-encodings" "cl-ppcre")
6 6
 	   :components ((:module "src"
7 7
 			   :components
8 8
 			   ((:file "package")
9 9
 			    (:file "misc")
10
+			    (:file "file")
10 11
 			    (:file "list")
12
+			    (:file "date")
11 13
 			    (:file "string/string")
12 14
 			    (:file "string/word")
13 15
 			    (:file "string/line")
... ...
@@ -27,6 +27,11 @@
27 27
     :getf-string
28 28
     :getf-strings
29 29
 
30
+    :getf-car
31
+    :getf-cars
32
+    :getf-cadr
33
+    :getf-cadrs
34
+
30 35
     :get-colon-values
31 36
     :remove-colon-values
32 37
     :replace-colon-value
... ...
@@ -272,6 +272,60 @@ Example:
272 272
     stack))
273 273
 
274 274
 
275
+;; LIST_OF_SUBLISTS STRING --> LIST_OF_SUBLISTS_WITH_STRING_AS_CAR
276
+(defun getf-cars (list value &key (stack '()) (test 'eq))
277
+  "Get items from list by an identifying string in `car`.
278
+  I.E., if the string is 'apple', any sublists like this:
279
+  ('apple' 1 2 3)
280
+  will be returned."
281
+
282
+  ;; just recurse through the list, adding each new matching
283
+  ;; item to the `stack`
284
+
285
+  (if (and (< 0 (length list)) (listp list))
286
+    (if (ignore-errors
287
+	  ;; the item might not be a list; for our purposes, let's ignore that.
288
+	  (funcall test
289
+	    (car (car list))    ;; '( ( here ) )
290
+	    value))
291
+      (getf-cars (cdr list) value
292
+		 :test test
293
+		 :stack (concatenate 'list stack (list (car list))))
294
+      (getf-cars (cdr list) value
295
+		 :stack stack
296
+		 :test test))
297
+    stack))
298
+
299
+(defun getf-car (list value &key (test 'eq))
300
+  (car (getf-cars list value :test test)))
301
+
302
+;; LIST_OF_SUBLISTS STRING --> LIST_OF_SUBLISTS_WITH_STRING_AS_CAR
303
+(defun getf-cadrs (list value &key (stack '()) (test 'eq))
304
+  "Get items from list by an identifying string in `car`.
305
+  I.E., if the string is 'apple', any sublists like this:
306
+  ('apple' 1 2 3)
307
+  will be returned."
308
+
309
+  ;; just recurse through the list, adding each new matching
310
+  ;; item to the `stack`
311
+
312
+  (if (and (< 0 (length list)) (listp list))
313
+    (if (ignore-errors
314
+	  ;; the item might not be a list; for our purposes, let's ignore that.
315
+	  (funcall test
316
+	    (cadr (car list))    ;; '( ( here ) )
317
+	    value))
318
+      (getf-cadrs (cdr list) value
319
+		 :test test
320
+		 :stack (concatenate 'list stack (list (car list))))
321
+      (getf-cadrs (cdr list) value
322
+		 :stack stack
323
+		 :test test))
324
+    stack))
325
+
326
+(defun getf-cadr (list value &key (test 'eq))
327
+  (car (getf-cadrs list value :test test)))
328
+
275 329
 ;; ---------------------------------------- 
276 330
 
277 331