diff --git a/src/ikarus.boot b/src/ikarus.boot index a1f4b33..eff73b6 100644 Binary files a/src/ikarus.boot and b/src/ikarus.boot differ diff --git a/src/ikarus.core.ss b/src/ikarus.core.ss index 4662ecb..39fe137 100644 --- a/src/ikarus.core.ss +++ b/src/ikarus.core.ss @@ -65,71 +65,8 @@ -(primitive-set! 'memq - (letrec ([race - (lambda (h t ls x) - (if (pair? h) - (if (eq? ($car h) x) - h - (let ([h ($cdr h)]) - (if (pair? h) - (if (eq? ($car h) x) - h - (if (not (eq? h t)) - (race ($cdr h) ($cdr t) ls x) - (error 'memq "circular list ~s" ls))) - (if (null? h) - '#f - (error 'memq "~s is not a proper list" ls))))) - (if (null? h) - '#f - (error 'memq "~s is not a proper list" ls))))]) - (lambda (x ls) - (race ls ls ls x)))) -(primitive-set! 'memv - (letrec ([race - (lambda (h t ls x) - (if (pair? h) - (if (eqv? ($car h) x) - h - (let ([h ($cdr h)]) - (if (pair? h) - (if (eqv? ($car h) x) - h - (if (not (eq? h t)) - (race ($cdr h) ($cdr t) ls x) - (error 'memv "circular list ~s" ls))) - (if (null? h) - '#f - (error 'memv "~s is not a proper list" ls))))) - (if (null? h) - '#f - (error 'memv "~s is not a proper list" ls))))]) - (lambda (x ls) - (race ls ls ls x)))) -(primitive-set! 'member - (letrec ([race - (lambda (h t ls x) - (if (pair? h) - (if (equal? ($car h) x) - h - (let ([h ($cdr h)]) - (if (pair? h) - (if (equal? ($car h) x) - h - (if (not (eq? h t)) - (race ($cdr h) ($cdr t) ls x) - (error 'member "circular list ~s" ls))) - (if (null? h) - '#f - (error 'member "~s is not a proper list" ls))))) - (if (null? h) - '#f - (error 'member "~s is not a proper list" ls))))]) - (lambda (x ls) - (race ls ls ls x)))) diff --git a/src/ikarus.lists.ss b/src/ikarus.lists.ss index 02ccbf3..982103b 100644 --- a/src/ikarus.lists.ss +++ b/src/ikarus.lists.ss @@ -1,10 +1,10 @@ (library (ikarus lists) - (export $memq list? reverse last-pair) + (export $memq list? reverse last-pair memq memv member) (import (only (scheme) $car $cdr) - (except (ikarus) list? reverse last-pair)) + (except (ikarus) list? reverse last-pair memq memv member)) (define $memq (lambda (x ls) @@ -61,8 +61,72 @@ (let ([d (cdr x)]) (race d d x x)) (error 'last-pair "~s is not a pair" x))))) - + (define memq + (letrec ([race + (lambda (h t ls x) + (if (pair? h) + (if (eq? ($car h) x) + h + (let ([h ($cdr h)]) + (if (pair? h) + (if (eq? ($car h) x) + h + (if (not (eq? h t)) + (race ($cdr h) ($cdr t) ls x) + (error 'memq "circular list ~s" ls))) + (if (null? h) + '#f + (error 'memq "~s is not a proper list" ls))))) + (if (null? h) + '#f + (error 'memq "~s is not a proper list" ls))))]) + (lambda (x ls) + (race ls ls ls x)))) + + (define memv + (letrec ([race + (lambda (h t ls x) + (if (pair? h) + (if (eqv? ($car h) x) + h + (let ([h ($cdr h)]) + (if (pair? h) + (if (eqv? ($car h) x) + h + (if (not (eq? h t)) + (race ($cdr h) ($cdr t) ls x) + (error 'memv "circular list ~s" ls))) + (if (null? h) + '#f + (error 'memv "~s is not a proper list" ls))))) + (if (null? h) + '#f + (error 'memv "~s is not a proper list" ls))))]) + (lambda (x ls) + (race ls ls ls x)))) + (define member + (letrec ([race + (lambda (h t ls x) + (if (pair? h) + (if (equal? ($car h) x) + h + (let ([h ($cdr h)]) + (if (pair? h) + (if (equal? ($car h) x) + h + (if (not (eq? h t)) + (race ($cdr h) ($cdr t) ls x) + (error 'member "circular list ~s" ls))) + (if (null? h) + '#f + (error 'member "~s is not a proper list" ls))))) + (if (null? h) + '#f + (error 'member "~s is not a proper list" ls))))]) + (lambda (x ls) + (race ls ls ls x)))) + )