From 71b0f8c686c207833d7e5c415ac0427020de29c7 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sat, 9 Nov 2013 16:45:04 +0900 Subject: [PATCH] add memv, assv, member, and assoc --- piclib/built-in.scm | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 3d458864..73edb31a 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -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)))))