3.10 Mutable Pairs and Lists
A mutable pair is like a pair created by cons, but it supports set-mcar! and set-mcdr! mutation operations to change the parts of the pair (like traditional Lisp and Scheme pairs).
A mutable list is analogous to a list created with pairs, but instead created with mutable pairs.
3.10.1 Mutable Pair Constructors and Selectors
v : any/c |
Returns #t if v is a mutable pair, #f otherwise.
a : any/c |
d : any/c |
Returns a mutable pair whose first element is a and second element is d.
p : mpair? |
Returns the first element of the mutable pair p.
p : mpair? |
Returns the second element of the mutable pair p.
p : mpair? |
v : any/v |
Changes the mutable pair p so that its first element is v.
p : mpair? |
v : any/v |
Changes the mutable pair p so that its second element is v.
3.10.2 Mutable List Functions
The bindings documented in this section are provided by the scheme/mpair library, not scheme/base or scheme.
For functions described in this section, contracts are not directly enforced. In particular, when a mutable list is expected, supplying any other kind of value (or mutating a value that starts as a list) tends to produce an exception from mcar or mcdr.
v : any/c |
Returns #t if v is a mutable list: either the empty list, or a mutable pair whose second element is a mutable list.
v : any/c |
Returns a newly allocated mutable list containing the vs as its elements.
(list->mlist lst) → mlist? |
lst : list? |
Returns a newly allocated mutable list with the same elements as lst.
(mlist->list mlst) → list? |
mlst : mlist? |
Returns a newly allocated list with the same elements as nlst.
(mlength mlst) → nonnegative-exact-integer? |
mlst : mlist? |
Returns the number of elements in mlst.
mlst : mlist? |
pos : nonnegative-exact-integer? |
Like list-ref, but for mutable lists.
(mlist-tail mlst pos) → any/c |
mlst : mlist? |
pos : nonnegative-exact-integer? |
Like list-tail, but for mutable lists.
mlst : mlist? |
mlst : mlist? |
v : any/c |
Like append, but for mutable lists.
mlst : mlist? |
mlst : mlist? |
v : any/c |
The mappend! procedure appends the given lists by mutating the tail of each to refer to the next, using set-mcdr!. Empty lists are dropped; in particular, the result of calling mappend! with one or more empty lists is the same as the result of the call with the empty lists removed from the set of arguments.
mlst : mlist? |
Like reverse, but for mutable lists.
mlst : mlist? |
Like mreverse, but destructively reverses the list by using all of the mutable pairs in mlst and changing them with set-mcdr!.
proc : procedure? |
mlst : mlist? |
Like map, but for mutable lists.
proc : procedure? |
mlst : mlist? |
Like for-each, but for mutable lists.
v : any/c |
mlst : mlist? |
Like member, but for mutable lists.
v : any/c |
mlst : mlist? |
Like memv, but for mutable lists.
v : any/c |
mlst : mlist? |
Like memq, but for mutable lists.
v : any/c |
Like assoc, but for mutable lists of mutable pairs.
v : any/c |
Like assv, but for mutable lists of mutable pairs.
v : any/c |
Like assq, but for mutable lists of mutable pairs.
Returns a procedure that returns #t when given a mutable list for which pred returns a true value for all elements.