Browse code
Add v-assoc for assoc in vectors
Showing 2 changed files
... | ... |
@@ -2,13 +2,20 @@ |
2 | 2 |
|
3 | 3 |
(defmacro vector-destructuring-bind ((&rest symbols) vector &body body) |
4 | 4 |
(let ((mappings (loop for symbol in symbols |
5 |
- for num from 0 |
|
6 |
- collect (list num symbol)))) |
|
5 |
+ for num from 0 |
|
6 |
+ collect (list num symbol)))) |
|
7 | 7 |
(once-only (vector) |
8 | 8 |
`(symbol-macrolet ,(mapcar (destructuring-lambda ((num symbol)) |
9 |
- `(,symbol (aref ,vector ,num))) |
|
10 |
- mappings) |
|
11 |
- ,@body)))) |
|
9 |
+ `(,symbol (aref ,vector ,num))) |
|
10 |
+ mappings) |
|
11 |
+ ,@body)))) |
|
12 |
+ |
|
13 |
+(defun v-assoc (item vector &key test test-not key) |
|
14 |
+ (loop for cur across vector |
|
15 |
+ for assoc-key = (car cur) |
|
16 |
+ for keyed = (if key (funcall key assoc-key) assoc-key) |
|
17 |
+ when (and test (funcall test keyed)) do (return cur) |
|
18 |
+ when (and test-not (not (funcall test keyed))) do (return cur))) |
|
12 | 19 |
|
13 | 20 |
(defun v-first (vector) |
14 | 21 |
(elt vector 0)) |