MannfromReno
MannfromReno

Reputation: 1276

Similar procedure to assoc that returns list of matching items

I'm not aware of any built in Scheme procedures that will take a key and return a list. Example:

(define data-a '((a 1) (b 2) (c 3) (a 4)))
(assoc 'a data-a)

That would return something like:

((a 1)(a 4))

Has anyone encountered anything similar? Thanks.

Upvotes: 0

Views: 53

Answers (1)

C. K. Young
C. K. Young

Reputation: 223013

It's easy to write one:

(define (assoc-all key alist)
  (filter (lambda (a) (equal? key (car a))) alist))

Upvotes: 3

Related Questions