From b62fef320b873578f7d5c9e2dde8f2e237ed1c4c Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Wed, 23 Apr 2008 15:03:11 +0000 Subject: [PATCH] documented new scheme/list functions svn: r9426 --- collects/scribblings/reference/pairs.scrbl | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/collects/scribblings/reference/pairs.scrbl b/collects/scribblings/reference/pairs.scrbl index 85c21cfd11..0c72243a94 100644 --- a/collects/scribblings/reference/pairs.scrbl +++ b/collects/scribblings/reference/pairs.scrbl @@ -480,7 +480,8 @@ Like @scheme[assoc], but finds an element using the predicate @note-lib[scheme/list] @(define list-eval (make-base-eval)) -@interaction-eval[#:eval list-eval (require scheme/list)] +@(interaction-eval #:eval list-eval + (require scheme/list (only-in scheme/function negate))) @defthing[empty null?]{The empty list.} @@ -512,6 +513,9 @@ Like @scheme[assoc], but finds an element using the predicate @defproc[(last [lst list?]) any]{Returns the last element of the list.} +@defproc[(last-pair [p pair?]) pair?]{ +Returns the last pair of a (possibly improper) list.} + @defproc[(drop [lst any/c] [pos nonnegative-exact-integer?]) list?]{ Synonym for @scheme[list-tail]. } @@ -564,11 +568,40 @@ pairs are interior nodes, and the resulting list contains all of the non-@scheme[null] leaves of the tree in the same order as an inorder traversal. -@examples[#:eval list-eval +@examples[#:eval list-eval (flatten '((a) b (c (d) . e) ())) (flatten 'a) ]} +@defproc[(remove-duplicates [lst list?] [proc procedure? equal?]) + list?]{ +Returns a list that has all items in @scheme[lst], but without +duplicate items. The resulting list is in the same order as +@scheme[lst], and for any item that occurs multiple times, the first +one is kept. @scheme[proc] is used for comparing items. + +@examples[#:eval list-eval + (remove-duplicates '(a b b a)) +]} + +@defproc[(filter-map [proc procedure?] [lst list?] ...+) + list?]{ +Like @scheme[map], but the resulting list does not contain any +@scheme[#f] values. In other words, @scheme[(filter-map p lst)] is +like @scheme[(filter (lambda (x) x) (map p lst))], except that it is +more efficient since no intermediate list is built.} + +@defproc[(partition [proc procedure?] [lst list?]) + list?]{ +Similar to @scheme[filter], except that two values are returned: the +items that satisfied the given @scheme[proc] predicate, and the items +that did not satisfy it. It is slightly more efficient than +@scheme[(values (filter proc lst) (filter (negate proc lst)))]. + +@examples[#:eval list-eval + (partition even? '(1 2 3 4 5 6)) +]} + @; ---------------------------------------- @section{Immutable Cyclic Data}