diff --git a/module/mes/scm.mes b/module/mes/scm.mes index 438568ad..805b0318 100644 --- a/module/mes/scm.mes +++ b/module/mes/scm.mes @@ -109,7 +109,7 @@ (define assv-ref assq-ref) (define (assoc key alist) - (if (null? alist) #f ;; IF + (if (null? alist) #f (if (equal? key (caar alist)) (car alist) (assoc key (cdr alist))))) @@ -124,14 +124,10 @@ (let ((entry (set-cdr! entry value))) alist)))) -(define (memq x lst) - (if (null? lst) #f ;; IF - (if (eq? x (car lst)) lst - (memq x (cdr lst))))) (define memv memq) (define (member x lst) - (if (null? lst) #f ;; IF + (if (null? lst) #f (if (equal? x (car lst)) lst (member x (cdr lst))))) diff --git a/src/lib.c b/src/lib.c index 91497418..f660b8f6 100644 --- a/src/lib.c +++ b/src/lib.c @@ -243,3 +243,28 @@ xassq (SCM x, SCM a) ///for speed in core only while (a != cell_nil && x != CDAR (a)) a = CDR (a); return a != cell_nil ? CAR (a) : cell_f; } + +SCM +memq (SCM x, SCM a) +{ + switch (TYPE (x)) + { + case TCHAR: + case TNUMBER: + { + SCM v = VALUE (x); + while (a != cell_nil && v != VALUE (CAR (a))) a = CDR (a); break; + } + case TKEYWORD: + { + SCM v = STRING (x); + while (a != cell_nil && v != STRING (CAR (a))) a = CDR (a); break; + } + // case TSYMBOL: + // case TSPECIAL: + default: + while (a != cell_nil && x != CAR (a)) a = CDR (a); break; + } + return a != cell_nil ? a : cell_f; +} +