add memv, assv, member, and assoc
This commit is contained in:
parent
c211d9ffde
commit
71b0f8c686
|
@ -104,6 +104,13 @@
|
|||
list
|
||||
(memq obj (cdr list)))))
|
||||
|
||||
(define (memv obj list)
|
||||
(if (null? list)
|
||||
#f
|
||||
(if (eqv? obj (car list))
|
||||
list
|
||||
(memq obj (cdr list)))))
|
||||
|
||||
(define (assq obj list)
|
||||
(if (null? list)
|
||||
#f
|
||||
|
@ -111,6 +118,13 @@
|
|||
(car list)
|
||||
(assq obj (cdr list)))))
|
||||
|
||||
(define (assv obj list)
|
||||
(if (null? list)
|
||||
#f
|
||||
(if (eqv? obj (caar list))
|
||||
(car list)
|
||||
(assq obj (cdr list)))))
|
||||
|
||||
(define (list-copy obj)
|
||||
(if (null? obj)
|
||||
obj
|
||||
|
@ -183,3 +197,18 @@
|
|||
(else
|
||||
#f)))
|
||||
|
||||
(define (member obj list . opts)
|
||||
(let ((compare (if (null? opts) equal? (car opts))))
|
||||
(if (null? list)
|
||||
#f
|
||||
(if (compare obj (car list))
|
||||
list
|
||||
(member obj (cdr list) compare)))))
|
||||
|
||||
(define (assoc obj list . opts)
|
||||
(let ((compare (if (null? opts) equal? (car opts))))
|
||||
(if (null? list)
|
||||
#f
|
||||
(if (compare obj (caar list))
|
||||
(car list)
|
||||
(assoc obj (cdr list) compare)))))
|
||||
|
|
Loading…
Reference in New Issue