11 Lists

▼ |  | Unstable

1 | Guidelines for developing unstable libraries
2 | Bytes
3 | Classes and Objects
4 | Contracts
5 | Definitions
6 | Dictionaries
7 | Directories
8 | Exceptions
9 | Filesystem
10 | Functions
11 | Lists
12 | Net
13 | Path
14 | PLane T Packages
15 | Ports
16 | Pretty-Printing
17 | Regular Expressions
18 | Requiring Modules
19 | Sandboxed Evaluation
20 | Scribble Documentation
21 | Sets
22 | S-Expression Diff
23 | Source Locations
24 | Strings
25 | Structs
26 | Syntax
27 | Planet Package Macros
28 | Text Representations
29 | Multiple Values
30 | XML and CSS
31 | Polymorphic Contracts
32 | Finding Mutated Variables
33 | Find
34 | Interface-Oriented Programming for Classes
35 | Sequences
36 | Hash Tables
37 | Match
38 | Generics
39 | Mark Parameters
40 | Debugging
41 | Contracts for macro subexpressions
42 | GUI libraries

On this page:

list-prefix?
filter-multiple
extend
check-duplicate
map/ values
remf

top← prev up next →

### 11`` 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 c> #t) (#<syntax:10:0 a> #t) (#<syntax:10:0 b> #t) (#<syntax:10:0 d> #t))

> > > The subsequent bindings were added by Carl Eastlund.

( map/values n f lst ...)

→

( listof B_1) |  | ... |  | ( listof B_n)

n : natural-number/c
f : (-> A ... ( values B_1 ... B_n))
lst : ( listof A)

Produces lists of the respective values of f applied to the elements in lst ... sequentially.

Example:

> ( map/values
3
( lambda (x)
( values (+ x 1) x (- x 1)))
( list 1 2 3))

'(2 3 4)
'(1 2 3)
'(0 1 2)

> > > The subsequent bindings were added by David Van Horn.

( remf pred lst) → list?
pred : procedure?
lst : list?

Returns a list that is like lst, omitting the first element of lst for which pred produces a true value.

Example:
> ( remf negative? '(1 -2 3 4 -5))
'(1 3 4 -5)

top← prev up next →