diff options
author | Maxime Devos <maximedevos@telenet.be> | 2023-02-01 15:40:47 +0100 |
---|---|---|
committer | Maxime Devos <maximedevos@telenet.be> | 2023-02-02 18:48:39 +0100 |
commit | 3cb4d0007ad2c0a130348ab398c11965a02be8bb (patch) | |
tree | 90981f14fff655eed38e6ecfe60fcb850468d431 | |
parent | 78f26c50b2cbde550061ad65ad82f1ddeb01d6a1 (diff) | |
download | gnunet-scheme-3cb4d0007ad2c0a130348ab398c11965a02be8bb.tar.gz gnunet-scheme-3cb4d0007ad2c0a130348ab398c11965a02be8bb.zip |
doc/typeclasses: Document cisw types.
This will simplify some other documentation later.
-rw-r--r-- | doc/typeclasses.tm | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/doc/typeclasses.tm b/doc/typeclasses.tm index 1f92061..f0430cf 100644 --- a/doc/typeclasses.tm +++ b/doc/typeclasses.tm | |||
@@ -39,6 +39,42 @@ | |||
39 | <\todo> | 39 | <\todo> |
40 | todo | 40 | todo |
41 | </todo> | 41 | </todo> |
42 | |||
43 | <section|Cooperative immutable slice wrappers (<acronym|cisw>) | ||
44 | <index|cisw><index|cooperative immutable slice wrapper>><label|cisw> | ||
45 | |||
46 | Records in Scheme-GNUnet often contain bytevector slices. When constructing | ||
47 | such a record, it would be inefficient to copy the whole bytevector slice. | ||
48 | As such, constructors of such record types typically don't do that, then. | ||
49 | At the same time, it usually is expected that the record is fully | ||
50 | immutable, and hence that the contents of the slices it contains don't | ||
51 | change over time. However, sometimes the slices do change over time so a | ||
52 | copy needs to made even if it is somewhat inefficient. | ||
53 | |||
54 | Therefore, these record types have two constructors: a constructor | ||
55 | conventionally named <scm|type-name/share> that does not make a copy and | ||
56 | requires that the slices are unmodified as long as the constructed object | ||
57 | remains in use, and a constructor conventionally named <scm|type-name> that | ||
58 | does make a copy and does not impose such requirements. | ||
59 | |||
60 | Sometimes, you receive a record that is only valid for a limited duration, | ||
61 | because afterwards the slices will be modified. To extend the duration, it | ||
62 | then is required to make a <em|copy> of the record that contains a copy of | ||
63 | the bytevector slices, and use the copy instead of the original. Procedures | ||
64 | for making such copies are conventionally named <scm|copy-type-name>, can | ||
65 | be called as <scm|(copy-type-name <var|original-record>)> and return the | ||
66 | copy. | ||
67 | |||
68 | These kind of record types are called <acronym|cisw> in Scheme-GNUnet. You | ||
69 | can contribute to Scheme-GNUnet by finding a better acronym. | ||
70 | |||
71 | As the records are immutable, field accessors for slices will always return | ||
72 | a read-only bytevector slice, even if a read-write bytevector slice was | ||
73 | passed to the constructor and even if the copying constructor was used. | ||
74 | |||
75 | Because bytevector slices cannot be compared with <scm|equal?>, the same | ||
76 | holds for <acronym|cisw> types. Instead, <acronym|cisw> types define their | ||
77 | own equality procedures, conventionally named <scm|type-name=?>. | ||
42 | </body> | 78 | </body> |
43 | 79 | ||
44 | <\initial> | 80 | <\initial> |