forked from MicahElliott/vrod
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mpairs.txt
60 lines (43 loc) · 1.79 KB
/
mpairs.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 mutable
pair (like traditional Lisp and Scheme pairs).
A mutable list is analogous to a list created with pairs, but instead
created with mutable pairs.
A mutable pair is not a pair; they are completely separate datatypes.
Similarly, a mutable list is not a list, except that the empty list is
also the empty mutable list. Instead of programming with mutable pairs
and mutable lists, data structures such as pairs, lists, and hash tables
are practically always better choices.
A mutable list can be used as a single-valued sequence (see [missing]).
The elements of the mutable list serve as elements of the sequence. See
also in-mlist.
1. Mutable Pair Constructors and Selectors
*mpair?*
(mpair? v) -> boolean? ~
v : any/c ~
Returns #t if v is a mutable pair, #f otherwise.
*mcons*
(mcons a d) -> mpair? ~
a : any/c ~
d : any/c ~
Returns a newly allocated mutable pair whose first element is a and
second element is d.
*mcar*
(mcar p) -> any/c ~
p : mpair? ~
Returns the first element of the mutable pair p.
*mcdr*
(mcdr p) -> any/c ~
p : mpair? ~
Returns the second element of the mutable pair p.
*set-mcar!*
(set-mcar! p v) -> void? ~
p : mpair? ~
v : any/v ~
Changes the mutable pair p so that its first element is v.
*set-mcdr!*
(set-mcdr! p v) -> void? ~
p : mpair? ~
v : any/v ~
Changes the mutable pair p so that its second element is v.