▼ |  | Unstable

1 | Guidelines for developing unstable libraries
2 | Bytes
3 | Contracts
4 | Exceptions
5 | Lists
6 | Net
7 | Path
8 | Source Locations
9 | Strings
10 | Structs
11 | Syntax
12 | Anaphoric Contracts
13 | Finding Mutated Variables
14 | Find
15 | Interface-Oriented Programming for Classes
16 | Sequences
17 | Hash Tables
18 | Match
19 | Skip Lists
20 | Interval Maps
21 | GUI libraries

On this page:

list-prefix?
filter-multiple
extend
check-duplicate

top ← prev up next →

### 5`` Lists

( require unstable/list )

This library is unstable; compatibility will not be maintained. See Unstable for more information.

( list-prefix? l r) → boolean?
l : list?
r : list?

True if l is a prefix of r.

Example:
> ( list-prefix? '(1 2) '(1 2 3 4 5))
#t

> > > The subsequent bindings were added by Sam Tobin-Hochstadt.

( filter-multiple l f ...)

→

list? |  | ...

l : list?
f : procedure?

Produces ( values ( filter f l) ... ).

Example:
> ( filter-multiple ( list 1 2 3 4 5) even? odd? )
(2 4)
(1 3 5)

( extend l1 l2 v) → list?
l1 : list?
l2 : list?
v : any/c

Extends l2 to be as long as l1 by adding ( - ( length l1) ( length l2)) copies of v to the end of l2.

Example:
> ( extend '(1 2 3) '(a) 'b)
(a b b)

> > > The subsequent bindings were added by Ryan Culpepper.

( check-duplicate |  | lst |  |  |  |
| [ | #:key extract-key |  |  |  |
|  | #:same? same?]) |  | → |  | ( or/c any/c #f)

lst : list?
extract-key : ( -> any/c any/c ) = ( lambda (x) x)

same?

:

( or/c ( any/c any/c . -> . any/c )
dict? )

=

equal?

Returns the first duplicate item in lst. More precisely, it returns the first x such that there was a previous y where (same? (extract-key x) (extract-key y)).

The same? argument can either be an equivalence predicate such as equal? or eqv? or a dictionary. In the latter case, the elements of the list are mapped to #t in the dictionary until an element is discovered that is already mapped to a true value. The procedures equal?, eqv?, and eq? automatically use a dictionary for speed.

Examples:
> ( check-duplicate '(1 2 3 4))
#f
> ( check-duplicate '(1 2 3 2 1))
2
> ( check-duplicate '((a 1) (b 2) (a 3)) #:key car )
(a 3)
> ( define id-t ( make-free-id-table ))

> ( check-duplicate ( syntax->list #'(a b c d a b))
#:same? id-t)

#<syntax:10:0 a>
> ( dict-map id-t list )
((#<syntax:10:0 a> #t) (#<syntax:10:0 d> #t) (#<syntax:10:0 c> #t) (#<syntax:10:0 b> #t))

top ← prev up next →