Code: Select all
(assoc 1 '((3 4) (1 2))) → (1 2)
And if not,
1)What is the best way to get the index?
2):) Put it on _my_ wish list.
thanks
tim
Code: Select all
(assoc 1 '((3 4) (1 2))) → (1 2)
Code: Select all
(find '(1 *) '((2 3) (1 2)) match) => 1
Code: Select all
;; With 'all, return indexes for all occurances of 'key in 'lst. Without 'all return the index of the first occurance.
(define (getAssocPos key lst all)
(letn((cmp (fn(x) (= (x 0) key)))
(res (index cmp lst)))
(if (empty? res)
nil
(if all
res
(first res)))))
Code: Select all
(set 'member-list (assoc key parent-list))
;; all sorts of code including possible changes to 'member-list
----
----
(setf (assoc key parent-list) member-list) ;; we had to call 'assoc a second time. Redundant?
Code: Select all
(set 'member-list (assoc key parent-list)
'found $found)
;; all sorts of code including possible changes to 'member-list
----
----
(setf (parent-list found) member-list) ;; I'm assuming the Implicit indexing is more efficient
Code: Select all
(letn ((found getAssocPos(key lst)) (member-list (lst found))
(when found
;; all sorts of code including possible changes to 'member-list
----
----
)
(setf (parent-list found) member-list) ;; implicit indexing
) ;; end letn
Code: Select all
(define (transform-found-assoc item)
…
)
(setf (assoc key parent-list)
(transform-found-assoc $it))