* moved memq, memv, and member to ikarus.lists
This commit is contained in:
parent
4a24e5ed28
commit
6a381a70f8
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -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))))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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))))
|
||||
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue