A custom push-assoc
Posted: Sat May 03, 2008 8:02 pm
During the assoc discussion I came across a problem I'm sure I knew how to solve a year or two ago, but I can't figure out anymore.
I know I'll only have assoc lists of the form
I want to write a function like
The only way I could get it to work is if I instead had a global assoc-lst that I used.
Any suggestions on how to make this so I can pass in the assoc-lst ?
I tried using a define-macro but failed.
I think I'm just missing something obvious.
I know I'll only have assoc lists of the form
Code: Select all
((a (1 2)) (b (3 4)) ...)
Code: Select all
(push-assoc key value assoc-lst)
Code: Select all
(set 'alst '())
(define (push-assoc k v )
(if (lookup k alst)
(assoc-set (alst k) (list k (append (last $0) (list v))))
(push (list k (list v)) alst -1)))
I tried using a define-macro but failed.
I think I'm just missing something obvious.