diff --git a/src/ikarus.boot b/src/ikarus.boot index 8205ef5..7d70722 100644 Binary files a/src/ikarus.boot and b/src/ikarus.boot differ diff --git a/src/ikarus.lists.ss b/src/ikarus.lists.ss index 4e23508..ef7577e 100644 --- a/src/ikarus.lists.ss +++ b/src/ikarus.lists.ss @@ -1,14 +1,14 @@ (library (ikarus lists) (export $memq list? list cons* make-list append length list-ref reverse - last-pair memq memp memv member assq assp assv assoc + last-pair memq memp memv member find assq assp assv assoc remq remv remove remp filter map for-each andmap ormap list-tail) (import (ikarus system $fx) (ikarus system $pairs) (except (ikarus) list? list cons* make-list append reverse - last-pair length list-ref memq memp memv member assq - assp assv assoc remq remv remove remp filter + last-pair length list-ref memq memp memv member find + assq assp assv assoc remq remv remove remp filter map for-each andmap ormap list-tail)) (define $memq @@ -274,6 +274,31 @@ (error 'memp "~s is not a procedure" p)) (race ls ls ls p)))) + (define find + (letrec ([race + (lambda (h t ls p) + (if (pair? h) + (let ([a ($car h)]) + (if (p a) + a + (let ([h ($cdr h)]) + (if (pair? h) + (let ([a ($car h)]) + (if (p a) + a + (if (not (eq? h t)) + (race ($cdr h) ($cdr t) ls p) + (error 'find "circular list ~s" ls)))) + (if (null? h) + '#f + (error 'find "~s is not a proper list" ls)))))) + (if (null? h) + '#f + (error 'find "~s is not a proper list" ls))))]) + (lambda (p ls) + (unless (procedure? p) + (error 'find "~s is not a procedure" p)) + (race ls ls ls p)))) (define assq (letrec ([race diff --git a/src/makefile.ss b/src/makefile.ss index 4f46188..07fadd0 100755 --- a/src/makefile.ss +++ b/src/makefile.ss @@ -333,6 +333,7 @@ [remv i] [remove i] [filter i] + [find i] [list-sort i] [vector-sort i] [vector-sort! i] diff --git a/src/todo-r6rs.ss b/src/todo-r6rs.ss index f7fc248..7be1262 100755 --- a/src/todo-r6rs.ss +++ b/src/todo-r6rs.ss @@ -505,7 +505,7 @@ [assv C ls se] [cons* C ls] [filter C ls] - [find S ls] + [find C ls] [fold-left S ls] [fold-right S ls] [for-all S ls]