Debian Codegraph @

doc/ref/chap29_mj.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
7 <head>
8 <script type="text/javascript"
9 src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
10 </script>
11 <title>GAP (ref) - Chapter 29: Records</title>
12 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
13 <meta name="generator" content="GAPDoc2HTML" />
14 <link rel="stylesheet" type="text/css" href="manual.css" />
15 <script src="manual.js" type="text/javascript"></script>
16 <script type="text/javascript">overwriteStyle();</script>
17 </head>
18 <body class="chap29" onload="jscontent()">
19
20
21 <div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a> <a href="chap1_mj.html">1</a> <a href="chap2_mj.html">2</a> <a href="chap3_mj.html">3</a> <a href="chap4_mj.html">4</a> <a href="chap5_mj.html">5</a> <a href="chap6_mj.html">6</a> <a href="chap7_mj.html">7</a> <a href="chap8_mj.html">8</a> <a href="chap9_mj.html">9</a> <a href="chap10_mj.html">10</a> <a href="chap11_mj.html">11</a> <a href="chap12_mj.html">12</a> <a href="chap13_mj.html">13</a> <a href="chap14_mj.html">14</a> <a href="chap15_mj.html">15</a> <a href="chap16_mj.html">16</a> <a href="chap17_mj.html">17</a> <a href="chap18_mj.html">18</a> <a href="chap19_mj.html">19</a> <a href="chap20_mj.html">20</a> <a href="chap21_mj.html">21</a> <a href="chap22_mj.html">22</a> <a href="chap23_mj.html">23</a> <a href="chap24_mj.html">24</a> <a href="chap25_mj.html">25</a> <a href="chap26_mj.html">26</a> <a href="chap27_mj.html">27</a> <a href="chap28_mj.html">28</a> <a href="chap29_mj.html">29</a> <a href="chap30_mj.html">30</a> <a href="chap31_mj.html">31</a> <a href="chap32_mj.html">32</a> <a href="chap33_mj.html">33</a> <a href="chap34_mj.html">34</a> <a href="chap35_mj.html">35</a> <a href="chap36_mj.html">36</a> <a href="chap37_mj.html">37</a> <a href="chap38_mj.html">38</a> <a href="chap39_mj.html">39</a> <a href="chap40_mj.html">40</a> <a href="chap41_mj.html">41</a> <a href="chap42_mj.html">42</a> <a href="chap43_mj.html">43</a> <a href="chap44_mj.html">44</a> <a href="chap45_mj.html">45</a> <a href="chap46_mj.html">46</a> <a href="chap47_mj.html">47</a> <a href="chap48_mj.html">48</a> <a href="chap49_mj.html">49</a> <a href="chap50_mj.html">50</a> <a href="chap51_mj.html">51</a> <a href="chap52_mj.html">52</a> <a href="chap53_mj.html">53</a> <a href="chap54_mj.html">54</a> <a href="chap55_mj.html">55</a> <a href="chap56_mj.html">56</a> <a href="chap57_mj.html">57</a> <a href="chap58_mj.html">58</a> <a href="chap59_mj.html">59</a> <a href="chap60_mj.html">60</a> <a href="chap61_mj.html">61</a> <a href="chap62_mj.html">62</a> <a href="chap63_mj.html">63</a> <a href="chap64_mj.html">64</a> <a href="chap65_mj.html">65</a> <a href="chap66_mj.html">66</a> <a href="chap67_mj.html">67</a> <a href="chap68_mj.html">68</a> <a href="chap69_mj.html">69</a> <a href="chap70_mj.html">70</a> <a href="chap71_mj.html">71</a> <a href="chap72_mj.html">72</a> <a href="chap73_mj.html">73</a> <a href="chap74_mj.html">74</a> <a href="chap75_mj.html">75</a> <a href="chap76_mj.html">76</a> <a href="chap77_mj.html">77</a> <a href="chap78_mj.html">78</a> <a href="chap79_mj.html">79</a> <a href="chap80_mj.html">80</a> <a href="chap81_mj.html">81</a> <a href="chap82_mj.html">82</a> <a href="chap83_mj.html">83</a> <a href="chap84_mj.html">84</a> <a href="chap85_mj.html">85</a> <a href="chap86_mj.html">86</a> <a href="chap87_mj.html">87</a> <a href="chapBib_mj.html">Bib</a> <a href="chapInd_mj.html">Ind</a> </div>
22
23 <div class="chlinkprevnexttop">&nbsp;<a href="chap0_mj.html">[Top of Book]</a>&nbsp; <a href="chap0_mj.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap28_mj.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap30_mj.html">[Next Chapter]</a>&nbsp; </div>
24
25 <p id="mathjaxlink" class="pcenter"><a href="chap29.html">[MathJax off]</a></p>
26 <p><a id="X7AA1073C7E943DD7" name="X7AA1073C7E943DD7"></a></p>
27 <div class="ChapSects"><a href="chap29_mj.html#X7AA1073C7E943DD7">29 <span class="Heading">Records</span></a>
28 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29_mj.html#X864F92347B5A3FF0">29.1 <span class="Heading">IsRecord and RecNames</span></a>
29 </span>
30 <div class="ContSSBlock">
31 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29_mj.html#X782A998E7D9EC406">29.1-1 IsRecord</a></span>
32 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29_mj.html#X837F1E1F866FB1A0">29.1-2 RecNames</a></span>
33 </div></div>
34 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29_mj.html#X7EAAE25D7A17F778">29.2 <span class="Heading">Accessing Record Elements</span></a>
35 </span>
36 </div>
37 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29_mj.html#X806DE3BD78742CA4">29.3 <span class="Heading">Record Assignment</span></a>
38 </span>
39 </div>
40 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29_mj.html#X86BC2672803863FB">29.4 <span class="Heading">Identical Records</span></a>
41 </span>
42 </div>
43 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29_mj.html#X83A7E6607B1D63BC">29.5 <span class="Heading">Comparisons of Records</span></a>
44 </span>
45 </div>
46 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29_mj.html#X79BE8D0E829E7ACE">29.6 <span class="Heading">IsBound and Unbind for Records</span></a>
47 </span>
48 <div class="ContSSBlock">
49 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29_mj.html#X7A13E8F87CAAA0AF">29.6-1 IsBound</a></span>
50 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29_mj.html#X7CA9AEFE7DB71604">29.6-2 Unbind</a></span>
51 </div></div>
52 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29_mj.html#X784897E180815EDA">29.7 <span class="Heading">Record Access Operations</span></a>
53 </span>
54 <div class="ContSSBlock">
55 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29_mj.html#X87BF90FA7F7A3B1B">29.7-1 NameRNam</a></span>
56 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29_mj.html#X78199B6B84A017B9">29.7-2 RNamObj</a></span>
57 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29_mj.html#X7821AC097821AC09"><code>29.7-3 \.</code></a></span>
58 </div></div>
59 </div>
60
61 <h3>29 <span class="Heading">Records</span></h3>
62
63 <p><em>Records</em> are next to lists the most important way to collect objects together. A record is a collection of <em>components</em>. Each component has a unique <em>name</em>, which is an identifier that distinguishes this component, and a <em>value</em>, which is an object of arbitrary type. We often abbreviate <em>value of a component</em> to <em>element</em>. We also say that a record <em>contains</em> its elements. You can access and change the elements of a record using its name.</p>
64
65 <p>Record literals are written by writing down the components in order between <q><code class="code">rec(</code></q> and <q><code class="code">)</code></q>, and separating them by commas <q><code class="code">,</code></q>. Each component consists of the name, the assignment operator <q><code class="code">:=</code></q>, and the value. The <em>empty record</em>, i.e., the record with no components, is written as <code class="code">rec()</code>.</p>
66
67
68 <div class="example"><pre>
69 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1, b := "2" ); # a record with two components</span>
70 rec( a := 1, b := "2" )
71 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1, b := rec( c := 2 ) ); # record may contain records</span>
72 rec( a := 1, b := rec( c := 2 ) )
73 </pre></div>
74
75 <p>We may use the <code class="func">Display</code> (<a href="chap6_mj.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>) function to illustrate the hierarchy of the record components.</p>
76
77
78 <div class="example"><pre>
79 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( last );</span>
80 rec(
81 a := 1,
82 b := rec(
83 c := 2 ) )
84 </pre></div>
85
86 <p>Records usually contain elements of various types, i.e., they are usually not homogeneous like lists.</p>
87
88 <p><a id="X864F92347B5A3FF0" name="X864F92347B5A3FF0"></a></p>
89
90 <h4>29.1 <span class="Heading">IsRecord and RecNames</span></h4>
91
92 <p><a id="X782A998E7D9EC406" name="X782A998E7D9EC406"></a></p>
93
94 <h5>29.1-1 IsRecord</h5>
95
96 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsRecord</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
97 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsRecordCollection</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
98 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsRecordCollColl</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
99
100 <div class="example"><pre>
101 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRecord( rec( a := 1, b := 2 ) );</span>
102 true
103 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRecord( IsRecord );</span>
104 false
105 </pre></div>
106
107 <p><a id="X837F1E1F866FB1A0" name="X837F1E1F866FB1A0"></a></p>
108
109 <h5>29.1-2 RecNames</h5>
110
111 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RecNames</code>( <var class="Arg">record</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
112 <p>returns a duplicate-free list of strings corresponding to the names of the record components of the record <var class="Arg">record</var>.</p>
113
114 <p>The list is sorted by <code class="func">RNamObj</code> (<a href="chap29_mj.html#X78199B6B84A017B9"><span class="RefLink">29.7-2</span></a>) for reasons of efficiency; see <code class="func">SortBy</code> (<a href="chap21_mj.html#X7FE4975F8166884D"><span class="RefLink">21.18-1</span></a>). Therefore the ordering is consistent within one <strong class="pkg">GAP</strong> session, but it is not necessarily consistent across different sessions. To obtain a result that is consistent across <strong class="pkg">GAP</strong> sessions, apply <code class="func">Set</code> (<a href="chap30_mj.html#X7E399AC97FD98217"><span class="RefLink">30.3-7</span></a>) to the returned list.</p>
115
116 <p>Note that given a string <code class="code">name</code> containing the name of a record component, you can access the record component via <code class="code"><var class="Arg">record</var>.(name)</code>, see Sections <a href="chap29_mj.html#X7EAAE25D7A17F778"><span class="RefLink">29.2</span></a> and <a href="chap29_mj.html#X806DE3BD78742CA4"><span class="RefLink">29.3</span></a>.</p>
117
118
119 <div class="example"><pre>
120 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
121 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Set(RecNames( r )); # 'Set' because ordering depends on GAP session</span>
122 [ "a", "b" ]
123 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Set(RecNames( r ), x -&gt; r.(x));</span>
124 [ 1, 2 ]
125 </pre></div>
126
127 <p>Note that it is most efficient to assign components to a (new or old) record in the order given by <code class="func">RecNames</code>.</p>
128
129 <p><a id="X7EAAE25D7A17F778" name="X7EAAE25D7A17F778"></a></p>
130
131 <h4>29.2 <span class="Heading">Accessing Record Elements</span></h4>
132
133 <p><code class="code"><var class="Arg">r</var>.<var class="Arg">name</var></code></p>
134
135 <p>The above construct evaluates to the value of the record component with the name <var class="Arg">name</var> in the record <var class="Arg">r</var>. Note that the <var class="Arg">name</var> is not evaluated, i.e. it is taken literal.</p>
136
137
138 <div class="example"><pre>
139 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
140 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r.a;</span>
141 1
142 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r.b;</span>
143 2
144 </pre></div>
145
146 <p><code class="code"><var class="Arg">r</var>.(<var class="Arg">name</var>)</code></p>
147
148 <p>This construct is similar to the above construct. The difference is that the second operand <var class="Arg">name</var> is evaluated. It must evaluate to a string or an integer otherwise an error is signalled. The construct then evaluates to the element of the record <var class="Arg">r</var> whose name is, as a string, equal to <var class="Arg">name</var>.</p>
149
150
151 <div class="example"><pre>
152 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">old := rec( a := 1, b := 2 );;</span>
153 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">new := rec();</span>
154 rec( )
155 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">for i in RecNames( old ) do</span>
156 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> new.(i) := old.(i);</span>
157 <span class="GAPprompt">&gt;</span> <span class="GAPinput">od;</span>
158 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( new );</span>
159 rec(
160 a := 1,
161 b := 2 )
162 </pre></div>
163
164 <p><a id="X806DE3BD78742CA4" name="X806DE3BD78742CA4"></a></p>
165
166 <h4>29.3 <span class="Heading">Record Assignment</span></h4>
167
168 <p><code class="code"><var class="Arg">r</var>.<var class="Arg">name</var> := <var class="Arg">obj</var></code></p>
169
170 <p>The record assignment assigns the object <var class="Arg">obj</var>, which may be an object of arbitrary type, to the record component with the name <var class="Arg">name</var>, which must be an identifier, of the record <var class="Arg">r</var>. That means that accessing the element with name <var class="Arg">name</var> of the record <var class="Arg">r</var> will return <var class="Arg">obj</var> after this assignment. If the record <var class="Arg">r</var> has no component with the name <var class="Arg">name</var>, the record is automatically extended to make room for the new component.</p>
171
172
173 <div class="example"><pre>
174 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
175 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r.a := 10;;</span>
176 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( r );</span>
177 rec(
178 a := 10,
179 b := 2 )
180 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r.c := 3;;</span>
181 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( r );</span>
182 rec(
183 a := 10,
184 b := 2,
185 c := 3 )
186 </pre></div>
187
188 <p>Note that assigning to a record changes the record.</p>
189
190 <p>The function <code class="func">IsBound</code> (<a href="chap29_mj.html#X7A13E8F87CAAA0AF"><span class="RefLink">29.6-1</span></a>) can be used to test if a record has a component with a certain name, the function <code class="func">Unbind</code> (<a href="chap29_mj.html#X7CA9AEFE7DB71604"><span class="RefLink">29.6-2</span></a>) can be used to remove a component with a certain name again.</p>
191
192
193 <div class="example"><pre>
194 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound(r.a);</span>
195 true
196 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound(r.d);</span>
197 false
198 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Unbind(r.b);</span>
199 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( r );</span>
200 rec(
201 a := 10,
202 c := 3 )
203 </pre></div>
204
205 <p><code class="code"><var class="Arg">r</var>.(<var class="Arg">name</var>) := <var class="Arg">obj</var></code></p>
206
207 <p>This construct is similar to the above construct. The difference is that the second operand <var class="Arg">name</var> is evaluated. It must evaluate to a string or an integer otherwise an error is signalled. The construct then assigns <var class="Arg">obj</var> to the record component of the record <var class="Arg">r</var> whose name is, as a string, equal to <var class="Arg">name</var>.</p>
208
209 <p><a id="X86BC2672803863FB" name="X86BC2672803863FB"></a></p>
210
211 <h4>29.4 <span class="Heading">Identical Records</span></h4>
212
213 <p>With the record assignment (see <a href="chap29_mj.html#X806DE3BD78742CA4"><span class="RefLink">29.3</span></a>) it is possible to change a record. This section describes the semantic consequences of this fact which are essentially the same as for lists (see <a href="chap21_mj.html#X7DD65BEA7EDB0CD7"><span class="RefLink">21.6</span></a>).</p>
214
215
216 <div class="example"><pre>
217 r := rec( a := 1 );
218 r := rec( a := 1, b := 2 );
219 </pre></div>
220
221 <p>The second assignment does not change the first record, instead it assigns a new record to the variable <code class="code">r</code>. On the other hand, in the following example the record is changed by the second assignment.</p>
222
223
224 <div class="example"><pre>
225 r := rec( a := 1 );
226 r.b := 2;
227 </pre></div>
228
229 <p>To understand the difference first think of a variable as a name for an object. The important point is that a record can have several names at the same time. An assignment <code class="code"><var class="Arg">var</var> := <var class="Arg">r</var></code> means in this interpretation that <var class="Arg">var</var> is a name for the object <var class="Arg">r</var>. At the end of the following example <code class="code">r2</code> still has the value <code class="code">rec( a := 1 )</code> as this record has not been changed and nothing else has been assigned to <code class="code">r2</code>.</p>
230
231
232 <div class="example"><pre>
233 r1 := rec( a := 1 );
234 r2 := r1;
235 r1 := rec( a := 1, b := 2 );
236 </pre></div>
237
238 <p>But after the following example the record for which <code class="code">r2</code> is a name has been changed and thus the value of <code class="code">r2</code> is now <code class="code">rec( a := 1, b := 2 )</code>.</p>
239
240
241 <div class="example"><pre>
242 r1 := rec( a := 1 );
243 r2 := r1;
244 r1.b := 2;
245 </pre></div>
246
247 <p>We shall say that two records are <em>identical</em> if changing one of them by a record assignment also changes the other one. This is slightly incorrect, because if <em>two</em> records are identical, there are actually only two names for <em>one</em> record. However, the correct usage would be very awkward and would only add to the confusion. Note that two identical records must be equal, because there is only one records with two different names. Thus identity is an equivalence relation that is a refinement of equality.</p>
248
249 <p>Let us now consider under which circumstances two records are identical.</p>
250
251 <p>If you enter a record literal then the record denoted by this literal is a new record that is not identical to any other record. Thus in the following example <code class="code">r1</code> and <code class="code">r2</code> are not identical, though they are equal of course.</p>
252
253
254 <div class="example"><pre>
255 r1 := rec( a := 1 );
256 r2 := rec( a := 1 );
257 </pre></div>
258
259 <p>Also in the following example, no records in the list <code class="code">l</code> are identical.</p>
260
261
262 <div class="example"><pre>
263 l := [];
264 for i in [1..10] do
265 l[i] := rec( a := 1 );
266 od;
267 </pre></div>
268
269 <p>If you assign a record to a variable no new record is created. Thus the record value of the variable on the left hand side and the record on the right hand side of the assignment are identical. So in the following example <code class="code">r1</code> and <code class="code">r2</code> are identical records.</p>
270
271
272 <div class="example"><pre>
273 r1 := rec( a := 1 );
274 r2 := r1;
275 </pre></div>
276
277 <p>If you pass a record as argument, the old record and the argument of the function are identical. Also if you return a record from a function, the old record and the value of the function call are identical. So in the following example <code class="code">r1</code> and <code class="code">r2</code> are identical records.</p>
278
279
280 <div class="example"><pre>
281 r1 := rec( a := 1 );
282 f := function ( r ) return r; end;
283 r2 := f( r1 );
284 </pre></div>
285
286 <p>The functions <code class="func">StructuralCopy</code> (<a href="chap12_mj.html#X7C1E70587EBDD2CB"><span class="RefLink">12.7-2</span></a>) and <code class="func">ShallowCopy</code> (<a href="chap12_mj.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) accept a record and return a new record that is equal to the old record but that is <em>not</em> identical to the old record. The difference between <code class="func">StructuralCopy</code> (<a href="chap12_mj.html#X7C1E70587EBDD2CB"><span class="RefLink">12.7-2</span></a>) and <code class="func">ShallowCopy</code> (<a href="chap12_mj.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) is that in the case of <code class="func">ShallowCopy</code> (<a href="chap12_mj.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) the corresponding components of the new and the old records will be identical, whereas in the case of <code class="func">StructuralCopy</code> (<a href="chap12_mj.html#X7C1E70587EBDD2CB"><span class="RefLink">12.7-2</span></a>) they will only be equal. So in the following example <code class="code">r1</code> and <code class="code">r2</code> are not identical records.</p>
287
288
289 <div class="example"><pre>
290 r1 := rec( a := 1 );
291 r2 := ShallowCopy( r1 );
292 </pre></div>
293
294 <p>If you change a record it keeps its identity. Thus if two records are identical and you change one of them, you also change the other, and they are still identical afterwards. On the other hand, two records that are not identical will never become identical if you change one of them. So in the following example both <code class="code">r1</code> and <code class="code">r2</code> are changed, and are still identical.</p>
295
296
297 <div class="example"><pre>
298 r1 := rec( a := 1 );
299 r2 := r1;
300 r1.b := 2;
301 </pre></div>
302
303 <p><a id="X83A7E6607B1D63BC" name="X83A7E6607B1D63BC"></a></p>
304
305 <h4>29.5 <span class="Heading">Comparisons of Records</span></h4>
306
307 <p><code class="code"><var class="Arg">rec1</var> = <var class="Arg">rec2</var></code></p>
308
309 <p><code class="code"><var class="Arg">rec1</var> &lt;&gt; <var class="Arg">rec2</var></code></p>
310
311 <p>Two records are considered equal, if for each component of one record the other record has a component of the same name with an equal value and vice versa.</p>
312
313
314 <div class="example"><pre>
315 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1, b := 2 ) = rec( b := 2, a := 1 );</span>
316 true
317 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1, b := 2 ) = rec( a := 2, b := 1 );</span>
318 false
319 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1 ) = rec( a := 1, b := 2 );</span>
320 false
321 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1 ) = 1;</span>
322 false
323 </pre></div>
324
325 <p><code class="code"><var class="Arg">rec1</var> &lt; <var class="Arg">rec2</var></code></p>
326
327 <p><code class="code"><var class="Arg">rec1</var> &lt;= <var class="Arg">rec2</var></code></p>
328
329 <p>To compare records we imagine that the components of both records are sorted according to their names (the sorting depends on the <strong class="pkg">GAP</strong> session, more precisely the order in which component names were first used). Then the records are compared lexicographically with unbound elements considered smaller than anything else. Precisely one record <var class="Arg">rec1</var> is considered less than another record <var class="Arg">rec2</var> if <var class="Arg">rec2</var> has a component with name <var class="Arg">name2</var> and either <var class="Arg">rec1</var> has no component with this name or <code class="code"><var class="Arg">rec1</var>.<var class="Arg">name2</var> &lt; <var class="Arg">rec2</var>.<var class="Arg">name2</var></code> and for each component of <var class="Arg">rec1</var> with name <code class="code"><var class="Arg">name1</var> &lt; <var class="Arg">name2</var></code> <var class="Arg">rec2</var> has a component with this name and <code class="code"><var class="Arg">rec1</var>.<var class="Arg">name1</var> = <var class="Arg">rec2</var>.<var class="Arg">name1</var></code>.</p>
330
331
332 <div class="example"><pre>
333 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( axy := 1, bxy := 2 ) &lt; rec( bxy := 2, axy := 1 ); # are equal</span>
334 false
335 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( axy := 1 ) &lt; rec( axy := 1, bxy := 2 ); # unbound is &lt; 2</span>
336 true
337 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># in new session the .axy components are compared first</span>
338 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( axy := 1, bxy := 2 ) &lt; rec( axy := 2, bxy := 0 ); # 1 &lt; 2</span>
339 true
340 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( axy := 1 ) &lt; rec( axy := 0, bxy := 2 ); # 0 &lt; 1</span>
341 false
342 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( bxy := 1 ) &lt; rec( bxy := 0, axy := 2 ); # unbound is &lt; 2</span>
343 true
344 </pre></div>
345
346 <p><a id="X79BE8D0E829E7ACE" name="X79BE8D0E829E7ACE"></a></p>
347
348 <h4>29.6 <span class="Heading">IsBound and Unbind for Records</span></h4>
349
350 <p><a id="X7A13E8F87CAAA0AF" name="X7A13E8F87CAAA0AF"></a></p>
351
352 <h5>29.6-1 IsBound</h5>
353
354 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsBound</code>( <var class="Arg">r.name</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
355 <p><code class="func">IsBound</code> returns <code class="keyw">true</code> if the record <var class="Arg">r</var> has a component with the name <var class="Arg">name</var> (which must be an identifier) and <code class="keyw">false</code> otherwise. <var class="Arg">r</var> must evaluate to a record, otherwise an error is signalled.</p>
356
357
358 <div class="example"><pre>
359 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
360 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound( r.a );</span>
361 true
362 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound( r.c );</span>
363 false
364 </pre></div>
365
366 <p><a id="X7CA9AEFE7DB71604" name="X7CA9AEFE7DB71604"></a></p>
367
368 <h5>29.6-2 Unbind</h5>
369
370 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Unbind</code>( <var class="Arg">r.name</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
371 <p><code class="func">Unbind</code> deletes the component with the name <var class="Arg">name</var> in the record <var class="Arg">r</var>. That is, after execution of <code class="func">Unbind</code>, <var class="Arg">r</var> no longer has a record component with this name. Note that it is not an error to unbind a nonexisting record component. <var class="Arg">r</var> must evaluate to a record, otherwise an error is signalled.</p>
372
373
374 <div class="example"><pre>
375 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
376 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Unbind( r.a ); r;</span>
377 rec( b := 2 )
378 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Unbind( r.c ); r;</span>
379 rec( b := 2 )
380 </pre></div>
381
382 <p>Note that <code class="func">IsBound</code> (<a href="chap29_mj.html#X7A13E8F87CAAA0AF"><span class="RefLink">29.6-1</span></a>) and <code class="func">Unbind</code> are special in that they do not evaluate their argument, otherwise <code class="func">IsBound</code> (<a href="chap29_mj.html#X7A13E8F87CAAA0AF"><span class="RefLink">29.6-1</span></a>) would always signal an error when it is supposed to return <code class="keyw">false</code> and there would be no way to tell <code class="func">Unbind</code> which component to remove.</p>
383
384 <p><a id="X784897E180815EDA" name="X784897E180815EDA"></a></p>
385
386 <h4>29.7 <span class="Heading">Record Access Operations</span></h4>
387
388 <p>Internally, record accesses are done using the operations listed in this section. For the records implemented in the kernel, kernel methods are provided for all these operations but otherwise it is possible to install methods for these operations for any object. This permits objects to simulate record behavior.</p>
389
390 <p>To save memory, records do not store a list of all component names, but only numbers identifying the components. There numbers are called <em>RNams</em>. <strong class="pkg">GAP</strong> keeps a global list of all RNams that are used and provides the functions <code class="func">NameRNam</code> (<a href="chap29_mj.html#X87BF90FA7F7A3B1B"><span class="RefLink">29.7-1</span></a>) and <code class="func">RNamObj</code> (<a href="chap29_mj.html#X78199B6B84A017B9"><span class="RefLink">29.7-2</span></a>) to translate RNams to strings that give the component names and vice versa.</p>
391
392 <p><a id="X87BF90FA7F7A3B1B" name="X87BF90FA7F7A3B1B"></a></p>
393
394 <h5>29.7-1 NameRNam</h5>
395
396 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NameRNam</code>( <var class="Arg">nr</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
397 <p>returns a string representing the component name corresponding to the RNam <var class="Arg">nr</var>.</p>
398
399 <p><a id="X78199B6B84A017B9" name="X78199B6B84A017B9"></a></p>
400
401 <h5>29.7-2 RNamObj</h5>
402
403 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RNamObj</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
404 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RNamObj</code>( <var class="Arg">int</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
405 <p>returns a number (the RNam) corresponding to the string <var class="Arg">str</var>. It is also possible to pass a positive integer <var class="Arg">int</var> in which case the decimal expansion of <var class="Arg">int</var> is used as a string.</p>
406
407
408 <div class="example"><pre>
409 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NameRNam(798);</span>
410 "BravaisSupergroups"
411 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RNamObj("blubberflutsch");</span>
412 2075
413 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NameRNam(last);</span>
414 "blubberflutsch"
415 </pre></div>
416
417 <p>The correspondence between strings and RNams is not predetermined ab initio, but RNams are assigned to component names dynamically on a <q>first come, first serve</q> basis. Therefore, depending on the version of the library you are using and on the assignments done so far, the <em>same</em> component name may be represented by <em>different</em> RNams in different <strong class="pkg">GAP</strong> sessions.</p>
418
419 <p><a id="X7821AC097821AC09" name="X7821AC097821AC09"></a></p>
420
421 <h5><code>29.7-3 \.</code></h5>
422
423 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; \.</code>( <var class="Arg">obj</var>, <var class="Arg">rnam</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
424 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsBound\.</code>( <var class="Arg">obj</var>, <var class="Arg">rnam</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
425 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; \.\:\=</code>( <var class="Arg">obj</var>, <var class="Arg">rnam</var>, <var class="Arg">val</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
426 <div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Unbind\.</code>( <var class="Arg">obj</var>, <var class="Arg">rnam</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
427 <p>These operations are called for record accesses to arbitrary objects. If applicable methods are installed, they are called when the object is accessed as a record.</p>
428
429 <p>For records, the operations implement component access, test for element boundness, component assignment and removal of the component represented by the RNam <var class="Arg">rnam</var>.</p>
430
431 <p>The component identifier <var class="Arg">rnam</var> is always required to be in <code class="func">IsPosInt</code> (<a href="chap14_mj.html#X82A854757DFA9C76"><span class="RefLink">14.2-2</span></a>).</p>
432
433
434 <div class="example"><pre>
435 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r:= rec( a:= 1 );;</span>
436 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound\.( r, RNamObj( "a" ) );</span>
437 true
438 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">\.( r, RNamObj( "a" ) );</span>
439 1
440 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound\.( r, RNamObj( "b" ) );</span>
441 false
442 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">\.\:\=( r, RNamObj( "b" ), 2 );</span>
443 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r;</span>
444 rec( a := 1, b := 2 )
445 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Unbind\.( r, RNamObj( "b" ) );</span>
446 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r;</span>
447 rec( a := 1 )
448 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">G:= SymmetricGroup( 4 );;</span>
449 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">G.1;</span>
450 (1,2,3,4)
451 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">\.( G, RNamObj( 1 ) );</span>
452 (1,2,3,4)
453 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">meth:= ApplicableMethod( \., [ G, 4711 ] );;</span>
454 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">meth( G, RNamObj( 1 ) );</span>
455 (1,2,3,4)
456 </pre></div>
457
458
459 <div class="chlinkprevnextbot">&nbsp;<a href="chap0_mj.html">[Top of Book]</a>&nbsp; <a href="chap0_mj.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap28_mj.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap30_mj.html">[Next Chapter]</a>&nbsp; </div>
460
461
462 <div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a> <a href="chap1_mj.html">1</a> <a href="chap2_mj.html">2</a> <a href="chap3_mj.html">3</a> <a href="chap4_mj.html">4</a> <a href="chap5_mj.html">5</a> <a href="chap6_mj.html">6</a> <a href="chap7_mj.html">7</a> <a href="chap8_mj.html">8</a> <a href="chap9_mj.html">9</a> <a href="chap10_mj.html">10</a> <a href="chap11_mj.html">11</a> <a href="chap12_mj.html">12</a> <a href="chap13_mj.html">13</a> <a href="chap14_mj.html">14</a> <a href="chap15_mj.html">15</a> <a href="chap16_mj.html">16</a> <a href="chap17_mj.html">17</a> <a href="chap18_mj.html">18</a> <a href="chap19_mj.html">19</a> <a href="chap20_mj.html">20</a> <a href="chap21_mj.html">21</a> <a href="chap22_mj.html">22</a> <a href="chap23_mj.html">23</a> <a href="chap24_mj.html">24</a> <a href="chap25_mj.html">25</a> <a href="chap26_mj.html">26</a> <a href="chap27_mj.html">27</a> <a href="chap28_mj.html">28</a> <a href="chap29_mj.html">29</a> <a href="chap30_mj.html">30</a> <a href="chap31_mj.html">31</a> <a href="chap32_mj.html">32</a> <a href="chap33_mj.html">33</a> <a href="chap34_mj.html">34</a> <a href="chap35_mj.html">35</a> <a href="chap36_mj.html">36</a> <a href="chap37_mj.html">37</a> <a href="chap38_mj.html">38</a> <a href="chap39_mj.html">39</a> <a href="chap40_mj.html">40</a> <a href="chap41_mj.html">41</a> <a href="chap42_mj.html">42</a> <a href="chap43_mj.html">43</a> <a href="chap44_mj.html">44</a> <a href="chap45_mj.html">45</a> <a href="chap46_mj.html">46</a> <a href="chap47_mj.html">47</a> <a href="chap48_mj.html">48</a> <a href="chap49_mj.html">49</a> <a href="chap50_mj.html">50</a> <a href="chap51_mj.html">51</a> <a href="chap52_mj.html">52</a> <a href="chap53_mj.html">53</a> <a href="chap54_mj.html">54</a> <a href="chap55_mj.html">55</a> <a href="chap56_mj.html">56</a> <a href="chap57_mj.html">57</a> <a href="chap58_mj.html">58</a> <a href="chap59_mj.html">59</a> <a href="chap60_mj.html">60</a> <a href="chap61_mj.html">61</a> <a href="chap62_mj.html">62</a> <a href="chap63_mj.html">63</a> <a href="chap64_mj.html">64</a> <a href="chap65_mj.html">65</a> <a href="chap66_mj.html">66</a> <a href="chap67_mj.html">67</a> <a href="chap68_mj.html">68</a> <a href="chap69_mj.html">69</a> <a href="chap70_mj.html">70</a> <a href="chap71_mj.html">71</a> <a href="chap72_mj.html">72</a> <a href="chap73_mj.html">73</a> <a href="chap74_mj.html">74</a> <a href="chap75_mj.html">75</a> <a href="chap76_mj.html">76</a> <a href="chap77_mj.html">77</a> <a href="chap78_mj.html">78</a> <a href="chap79_mj.html">79</a> <a href="chap80_mj.html">80</a> <a href="chap81_mj.html">81</a> <a href="chap82_mj.html">82</a> <a href="chap83_mj.html">83</a> <a href="chap84_mj.html">84</a> <a href="chap85_mj.html">85</a> <a href="chap86_mj.html">86</a> <a href="chap87_mj.html">87</a> <a href="chapBib_mj.html">Bib</a> <a href="chapInd_mj.html">Ind</a> </div>
463
464 <hr />
465 <p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
466 </body>
467 </html>