-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module (chicken locative)
74 lines (44 loc) · 2.11 KB
/
Module (chicken locative)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
[[tags: manual]]
[[toc:]]
== Module (chicken locative)
A ''locative'' is an object that points to an element of a containing object,
much like a ''pointer'' in low-level, imperative programming languages like ''C''. The element can
be accessed and changed indirectly, by performing access or change operations
on the locative. The container object can be computed by calling the
{{locative->object}} procedure.
Locatives may be passed to foreign procedures that expect pointer arguments.
The following procedures are provided by the {{(chicken locative)}}
module.
=== make-locative
<procedure>(make-locative OBJ [INDEX])</procedure>
Creates a locative that refers to the element of the non-immediate object
{{OBJ}} at position {{INDEX}}. {{OBJ}} may be a vector, pair, string, blob,
SRFI-4 number-vector, or record structure. {{INDEX}} should be a fixnum.
{{INDEX}} defaults to 0.
=== make-weak-locative
<procedure>(make-weak-locative OBJ [INDEX])</procedure>
Creates a ''weak'' locative. Even though the locative refers to an element of a container object,
the container object will still be reclaimed by garbage collection if no other references
to it exist.
=== locative?
<procedure>(locative? X)</procedure>
Returns {{#t}} if {{X}} is a locative, or {{#f}} otherwise.
=== locative-ref
<procedure>(locative-ref LOC)</procedure>
Returns the element to which the locative {{LOC}} refers. If the containing
object has been reclaimed by garbage collection, an error is signalled.
(locative-ref (make-locative "abc" 1)) ==> #\b
=== locative-set!
<procedure>(locative-set! LOC X)</procedure><br>
<procedure>(set! (locative-ref LOC) X)</procedure>
Changes the element to which the locative {{LOC}} refers to {{X}}.
If the containing
object has been reclaimed by garbage collection, an error is signalled.
=== locative->object
<procedure>(locative->object LOC)</procedure>
Returns the object that contains the element referred to by {{LOC}} or
{{#f}} if the container has been reclaimed by garbage collection.
(locative->object (make-locative "abc" 1)) ==> "abc"
---
Previous: [[Module (chicken load)]]
Next: [[Module (chicken memory)]]