Debian Codegraph @

doc/ref/chap29.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 <title>GAP (ref) - Chapter 29: Records</title>
9 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
10 <meta name="generator" content="GAPDoc2HTML" />
11 <link rel="stylesheet" type="text/css" href="manual.css" />
12 <script src="manual.js" type="text/javascript"></script>
13 <script type="text/javascript">overwriteStyle();</script>
14 </head>
15 <body class="chap29" onload="jscontent()">
16
17
18 <div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chap12.html">12</a> <a href="chap13.html">13</a> <a href="chap14.html">14</a> <a href="chap15.html">15</a> <a href="chap16.html">16</a> <a href="chap17.html">17</a> <a href="chap18.html">18</a> <a href="chap19.html">19</a> <a href="chap20.html">20</a> <a href="chap21.html">21</a> <a href="chap22.html">22</a> <a href="chap23.html">23</a> <a href="chap24.html">24</a> <a href="chap25.html">25</a> <a href="chap26.html">26</a> <a href="chap27.html">27</a> <a href="chap28.html">28</a> <a href="chap29.html">29</a> <a href="chap30.html">30</a> <a href="chap31.html">31</a> <a href="chap32.html">32</a> <a href="chap33.html">33</a> <a href="chap34.html">34</a> <a href="chap35.html">35</a> <a href="chap36.html">36</a> <a href="chap37.html">37</a> <a href="chap38.html">38</a> <a href="chap39.html">39</a> <a href="chap40.html">40</a> <a href="chap41.html">41</a> <a href="chap42.html">42</a> <a href="chap43.html">43</a> <a href="chap44.html">44</a> <a href="chap45.html">45</a> <a href="chap46.html">46</a> <a href="chap47.html">47</a> <a href="chap48.html">48</a> <a href="chap49.html">49</a> <a href="chap50.html">50</a> <a href="chap51.html">51</a> <a href="chap52.html">52</a> <a href="chap53.html">53</a> <a href="chap54.html">54</a> <a href="chap55.html">55</a> <a href="chap56.html">56</a> <a href="chap57.html">57</a> <a href="chap58.html">58</a> <a href="chap59.html">59</a> <a href="chap60.html">60</a> <a href="chap61.html">61</a> <a href="chap62.html">62</a> <a href="chap63.html">63</a> <a href="chap64.html">64</a> <a href="chap65.html">65</a> <a href="chap66.html">66</a> <a href="chap67.html">67</a> <a href="chap68.html">68</a> <a href="chap69.html">69</a> <a href="chap70.html">70</a> <a href="chap71.html">71</a> <a href="chap72.html">72</a> <a href="chap73.html">73</a> <a href="chap74.html">74</a> <a href="chap75.html">75</a> <a href="chap76.html">76</a> <a href="chap77.html">77</a> <a href="chap78.html">78</a> <a href="chap79.html">79</a> <a href="chap80.html">80</a> <a href="chap81.html">81</a> <a href="chap82.html">82</a> <a href="chap83.html">83</a> <a href="chap84.html">84</a> <a href="chap85.html">85</a> <a href="chap86.html">86</a> <a href="chap87.html">87</a> <a href="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
19
20 <div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap28.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap30.html">[Next Chapter]</a>&nbsp; </div>
21
22 <p id="mathjaxlink" class="pcenter"><a href="chap29_mj.html">[MathJax on]</a></p>
23 <p><a id="X7AA1073C7E943DD7" name="X7AA1073C7E943DD7"></a></p>
24 <div class="ChapSects"><a href="chap29.html#X7AA1073C7E943DD7">29 <span class="Heading">Records</span></a>
25 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29.html#X864F92347B5A3FF0">29.1 <span class="Heading">IsRecord and RecNames</span></a>
26 </span>
27 <div class="ContSSBlock">
28 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29.html#X782A998E7D9EC406">29.1-1 IsRecord</a></span>
29 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29.html#X837F1E1F866FB1A0">29.1-2 RecNames</a></span>
30 </div></div>
31 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29.html#X7EAAE25D7A17F778">29.2 <span class="Heading">Accessing Record Elements</span></a>
32 </span>
33 </div>
34 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29.html#X806DE3BD78742CA4">29.3 <span class="Heading">Record Assignment</span></a>
35 </span>
36 </div>
37 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29.html#X86BC2672803863FB">29.4 <span class="Heading">Identical Records</span></a>
38 </span>
39 </div>
40 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29.html#X83A7E6607B1D63BC">29.5 <span class="Heading">Comparisons of Records</span></a>
41 </span>
42 </div>
43 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29.html#X79BE8D0E829E7ACE">29.6 <span class="Heading">IsBound and Unbind for Records</span></a>
44 </span>
45 <div class="ContSSBlock">
46 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29.html#X7A13E8F87CAAA0AF">29.6-1 IsBound</a></span>
47 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29.html#X7CA9AEFE7DB71604">29.6-2 Unbind</a></span>
48 </div></div>
49 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap29.html#X784897E180815EDA">29.7 <span class="Heading">Record Access Operations</span></a>
50 </span>
51 <div class="ContSSBlock">
52 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29.html#X87BF90FA7F7A3B1B">29.7-1 NameRNam</a></span>
53 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29.html#X78199B6B84A017B9">29.7-2 RNamObj</a></span>
54 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap29.html#X7821AC097821AC09"><code>29.7-3 \.</code></a></span>
55 </div></div>
56 </div>
57
58 <h3>29 <span class="Heading">Records</span></h3>
59
60 <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>
61
62 <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>
63
64
65 <div class="example"><pre>
66 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1, b := "2" ); # a record with two components</span>
67 rec( a := 1, b := "2" )
68 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1, b := rec( c := 2 ) ); # record may contain records</span>
69 rec( a := 1, b := rec( c := 2 ) )
70 </pre></div>
71
72 <p>We may use the <code class="func">Display</code> (<a href="chap6.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>) function to illustrate the hierarchy of the record components.</p>
73
74
75 <div class="example"><pre>
76 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( last );</span>
77 rec(
78 a := 1,
79 b := rec(
80 c := 2 ) )
81 </pre></div>
82
83 <p>Records usually contain elements of various types, i.e., they are usually not homogeneous like lists.</p>
84
85 <p><a id="X864F92347B5A3FF0" name="X864F92347B5A3FF0"></a></p>
86
87 <h4>29.1 <span class="Heading">IsRecord and RecNames</span></h4>
88
89 <p><a id="X782A998E7D9EC406" name="X782A998E7D9EC406"></a></p>
90
91 <h5>29.1-1 IsRecord</h5>
92
93 <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>
94 <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>
95 <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>
96
97 <div class="example"><pre>
98 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRecord( rec( a := 1, b := 2 ) );</span>
99 true
100 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsRecord( IsRecord );</span>
101 false
102 </pre></div>
103
104 <p><a id="X837F1E1F866FB1A0" name="X837F1E1F866FB1A0"></a></p>
105
106 <h5>29.1-2 RecNames</h5>
107
108 <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>
109 <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>
110
111 <p>The list is sorted by <code class="func">RNamObj</code> (<a href="chap29.html#X78199B6B84A017B9"><span class="RefLink">29.7-2</span></a>) for reasons of efficiency; see <code class="func">SortBy</code> (<a href="chap21.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.html#X7E399AC97FD98217"><span class="RefLink">30.3-7</span></a>) to the returned list.</p>
112
113 <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.html#X7EAAE25D7A17F778"><span class="RefLink">29.2</span></a> and <a href="chap29.html#X806DE3BD78742CA4"><span class="RefLink">29.3</span></a>.</p>
114
115
116 <div class="example"><pre>
117 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
118 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Set(RecNames( r )); # 'Set' because ordering depends on GAP session</span>
119 [ "a", "b" ]
120 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Set(RecNames( r ), x -&gt; r.(x));</span>
121 [ 1, 2 ]
122 </pre></div>
123
124 <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>
125
126 <p><a id="X7EAAE25D7A17F778" name="X7EAAE25D7A17F778"></a></p>
127
128 <h4>29.2 <span class="Heading">Accessing Record Elements</span></h4>
129
130 <p><code class="code"><var class="Arg">r</var>.<var class="Arg">name</var></code></p>
131
132 <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>
133
134
135 <div class="example"><pre>
136 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
137 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r.a;</span>
138 1
139 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r.b;</span>
140 2
141 </pre></div>
142
143 <p><code class="code"><var class="Arg">r</var>.(<var class="Arg">name</var>)</code></p>
144
145 <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>
146
147
148 <div class="example"><pre>
149 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">old := rec( a := 1, b := 2 );;</span>
150 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">new := rec();</span>
151 rec( )
152 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">for i in RecNames( old ) do</span>
153 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> new.(i) := old.(i);</span>
154 <span class="GAPprompt">&gt;</span> <span class="GAPinput">od;</span>
155 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( new );</span>
156 rec(
157 a := 1,
158 b := 2 )
159 </pre></div>
160
161 <p><a id="X806DE3BD78742CA4" name="X806DE3BD78742CA4"></a></p>
162
163 <h4>29.3 <span class="Heading">Record Assignment</span></h4>
164
165 <p><code class="code"><var class="Arg">r</var>.<var class="Arg">name</var> := <var class="Arg">obj</var></code></p>
166
167 <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>
168
169
170 <div class="example"><pre>
171 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
172 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r.a := 10;;</span>
173 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( r );</span>
174 rec(
175 a := 10,
176 b := 2 )
177 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r.c := 3;;</span>
178 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( r );</span>
179 rec(
180 a := 10,
181 b := 2,
182 c := 3 )
183 </pre></div>
184
185 <p>Note that assigning to a record changes the record.</p>
186
187 <p>The function <code class="func">IsBound</code> (<a href="chap29.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.html#X7CA9AEFE7DB71604"><span class="RefLink">29.6-2</span></a>) can be used to remove a component with a certain name again.</p>
188
189
190 <div class="example"><pre>
191 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound(r.a);</span>
192 true
193 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound(r.d);</span>
194 false
195 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Unbind(r.b);</span>
196 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Display( r );</span>
197 rec(
198 a := 10,
199 c := 3 )
200 </pre></div>
201
202 <p><code class="code"><var class="Arg">r</var>.(<var class="Arg">name</var>) := <var class="Arg">obj</var></code></p>
203
204 <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>
205
206 <p><a id="X86BC2672803863FB" name="X86BC2672803863FB"></a></p>
207
208 <h4>29.4 <span class="Heading">Identical Records</span></h4>
209
210 <p>With the record assignment (see <a href="chap29.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.html#X7DD65BEA7EDB0CD7"><span class="RefLink">21.6</span></a>).</p>
211
212
213 <div class="example"><pre>
214 r := rec( a := 1 );
215 r := rec( a := 1, b := 2 );
216 </pre></div>
217
218 <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>
219
220
221 <div class="example"><pre>
222 r := rec( a := 1 );
223 r.b := 2;
224 </pre></div>
225
226 <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>
227
228
229 <div class="example"><pre>
230 r1 := rec( a := 1 );
231 r2 := r1;
232 r1 := rec( a := 1, b := 2 );
233 </pre></div>
234
235 <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>
236
237
238 <div class="example"><pre>
239 r1 := rec( a := 1 );
240 r2 := r1;
241 r1.b := 2;
242 </pre></div>
243
244 <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>
245
246 <p>Let us now consider under which circumstances two records are identical.</p>
247
248 <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>
249
250
251 <div class="example"><pre>
252 r1 := rec( a := 1 );
253 r2 := rec( a := 1 );
254 </pre></div>
255
256 <p>Also in the following example, no records in the list <code class="code">l</code> are identical.</p>
257
258
259 <div class="example"><pre>
260 l := [];
261 for i in [1..10] do
262 l[i] := rec( a := 1 );
263 od;
264 </pre></div>
265
266 <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>
267
268
269 <div class="example"><pre>
270 r1 := rec( a := 1 );
271 r2 := r1;
272 </pre></div>
273
274 <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>
275
276
277 <div class="example"><pre>
278 r1 := rec( a := 1 );
279 f := function ( r ) return r; end;
280 r2 := f( r1 );
281 </pre></div>
282
283 <p>The functions <code class="func">StructuralCopy</code> (<a href="chap12.html#X7C1E70587EBDD2CB"><span class="RefLink">12.7-2</span></a>) and <code class="func">ShallowCopy</code> (<a href="chap12.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.html#X7C1E70587EBDD2CB"><span class="RefLink">12.7-2</span></a>) and <code class="func">ShallowCopy</code> (<a href="chap12.html#X846BC7107C352031"><span class="RefLink">12.7-1</span></a>) is that in the case of <code class="func">ShallowCopy</code> (<a href="chap12.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.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>
284
285
286 <div class="example"><pre>
287 r1 := rec( a := 1 );
288 r2 := ShallowCopy( r1 );
289 </pre></div>
290
291 <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>
292
293
294 <div class="example"><pre>
295 r1 := rec( a := 1 );
296 r2 := r1;
297 r1.b := 2;
298 </pre></div>
299
300 <p><a id="X83A7E6607B1D63BC" name="X83A7E6607B1D63BC"></a></p>
301
302 <h4>29.5 <span class="Heading">Comparisons of Records</span></h4>
303
304 <p><code class="code"><var class="Arg">rec1</var> = <var class="Arg">rec2</var></code></p>
305
306 <p><code class="code"><var class="Arg">rec1</var> &lt;&gt; <var class="Arg">rec2</var></code></p>
307
308 <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>
309
310
311 <div class="example"><pre>
312 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1, b := 2 ) = rec( b := 2, a := 1 );</span>
313 true
314 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1, b := 2 ) = rec( a := 2, b := 1 );</span>
315 false
316 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1 ) = rec( a := 1, b := 2 );</span>
317 false
318 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( a := 1 ) = 1;</span>
319 false
320 </pre></div>
321
322 <p><code class="code"><var class="Arg">rec1</var> &lt; <var class="Arg">rec2</var></code></p>
323
324 <p><code class="code"><var class="Arg">rec1</var> &lt;= <var class="Arg">rec2</var></code></p>
325
326 <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>
327
328
329 <div class="example"><pre>
330 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( axy := 1, bxy := 2 ) &lt; rec( bxy := 2, axy := 1 ); # are equal</span>
331 false
332 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( axy := 1 ) &lt; rec( axy := 1, bxy := 2 ); # unbound is &lt; 2</span>
333 true
334 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># in new session the .axy components are compared first</span>
335 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( axy := 1, bxy := 2 ) &lt; rec( axy := 2, bxy := 0 ); # 1 &lt; 2</span>
336 true
337 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( axy := 1 ) &lt; rec( axy := 0, bxy := 2 ); # 0 &lt; 1</span>
338 false
339 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">rec( bxy := 1 ) &lt; rec( bxy := 0, axy := 2 ); # unbound is &lt; 2</span>
340 true
341 </pre></div>
342
343 <p><a id="X79BE8D0E829E7ACE" name="X79BE8D0E829E7ACE"></a></p>
344
345 <h4>29.6 <span class="Heading">IsBound and Unbind for Records</span></h4>
346
347 <p><a id="X7A13E8F87CAAA0AF" name="X7A13E8F87CAAA0AF"></a></p>
348
349 <h5>29.6-1 IsBound</h5>
350
351 <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>
352 <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>
353
354
355 <div class="example"><pre>
356 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
357 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound( r.a );</span>
358 true
359 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound( r.c );</span>
360 false
361 </pre></div>
362
363 <p><a id="X7CA9AEFE7DB71604" name="X7CA9AEFE7DB71604"></a></p>
364
365 <h5>29.6-2 Unbind</h5>
366
367 <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>
368 <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>
369
370
371 <div class="example"><pre>
372 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
373 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Unbind( r.a ); r;</span>
374 rec( b := 2 )
375 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Unbind( r.c ); r;</span>
376 rec( b := 2 )
377 </pre></div>
378
379 <p>Note that <code class="func">IsBound</code> (<a href="chap29.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.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>
380
381 <p><a id="X784897E180815EDA" name="X784897E180815EDA"></a></p>
382
383 <h4>29.7 <span class="Heading">Record Access Operations</span></h4>
384
385 <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>
386
387 <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.html#X87BF90FA7F7A3B1B"><span class="RefLink">29.7-1</span></a>) and <code class="func">RNamObj</code> (<a href="chap29.html#X78199B6B84A017B9"><span class="RefLink">29.7-2</span></a>) to translate RNams to strings that give the component names and vice versa.</p>
388
389 <p><a id="X87BF90FA7F7A3B1B" name="X87BF90FA7F7A3B1B"></a></p>
390
391 <h5>29.7-1 NameRNam</h5>
392
393 <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>
394 <p>returns a string representing the component name corresponding to the RNam <var class="Arg">nr</var>.</p>
395
396 <p><a id="X78199B6B84A017B9" name="X78199B6B84A017B9"></a></p>
397
398 <h5>29.7-2 RNamObj</h5>
399
400 <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>
401 <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>
402 <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>
403
404
405 <div class="example"><pre>
406 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NameRNam(798);</span>
407 "BravaisSupergroups"
408 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RNamObj("blubberflutsch");</span>
409 2075
410 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NameRNam(last);</span>
411 "blubberflutsch"
412 </pre></div>
413
414 <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>
415
416 <p><a id="X7821AC097821AC09" name="X7821AC097821AC09"></a></p>
417
418 <h5><code>29.7-3 \.</code></h5>
419
420 <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>
421 <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>
422 <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>
423 <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>
424 <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>
425
426 <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>
427
428 <p>The component identifier <var class="Arg">rnam</var> is always required to be in <code class="func">IsPosInt</code> (<a href="chap14.html#X82A854757DFA9C76"><span class="RefLink">14.2-2</span></a>).</p>
429
430
431 <div class="example"><pre>
432 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r:= rec( a:= 1 );;</span>
433 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound\.( r, RNamObj( "a" ) );</span>
434 true
435 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">\.( r, RNamObj( "a" ) );</span>
436 1
437 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsBound\.( r, RNamObj( "b" ) );</span>
438 false
439 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">\.\:\=( r, RNamObj( "b" ), 2 );</span>
440 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r;</span>
441 rec( a := 1, b := 2 )
442 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Unbind\.( r, RNamObj( "b" ) );</span>
443 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">r;</span>
444 rec( a := 1 )
445 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">G:= SymmetricGroup( 4 );;</span>
446 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">G.1;</span>
447 (1,2,3,4)
448 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">\.( G, RNamObj( 1 ) );</span>
449 (1,2,3,4)
450 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">meth:= ApplicableMethod( \., [ G, 4711 ] );;</span>
451 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">meth( G, RNamObj( 1 ) );</span>
452 (1,2,3,4)
453 </pre></div>
454
455
456 <div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap28.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap30.html">[Next Chapter]</a>&nbsp; </div>
457
458
459 <div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chap12.html">12</a> <a href="chap13.html">13</a> <a href="chap14.html">14</a> <a href="chap15.html">15</a> <a href="chap16.html">16</a> <a href="chap17.html">17</a> <a href="chap18.html">18</a> <a href="chap19.html">19</a> <a href="chap20.html">20</a> <a href="chap21.html">21</a> <a href="chap22.html">22</a> <a href="chap23.html">23</a> <a href="chap24.html">24</a> <a href="chap25.html">25</a> <a href="chap26.html">26</a> <a href="chap27.html">27</a> <a href="chap28.html">28</a> <a href="chap29.html">29</a> <a href="chap30.html">30</a> <a href="chap31.html">31</a> <a href="chap32.html">32</a> <a href="chap33.html">33</a> <a href="chap34.html">34</a> <a href="chap35.html">35</a> <a href="chap36.html">36</a> <a href="chap37.html">37</a> <a href="chap38.html">38</a> <a href="chap39.html">39</a> <a href="chap40.html">40</a> <a href="chap41.html">41</a> <a href="chap42.html">42</a> <a href="chap43.html">43</a> <a href="chap44.html">44</a> <a href="chap45.html">45</a> <a href="chap46.html">46</a> <a href="chap47.html">47</a> <a href="chap48.html">48</a> <a href="chap49.html">49</a> <a href="chap50.html">50</a> <a href="chap51.html">51</a> <a href="chap52.html">52</a> <a href="chap53.html">53</a> <a href="chap54.html">54</a> <a href="chap55.html">55</a> <a href="chap56.html">56</a> <a href="chap57.html">57</a> <a href="chap58.html">58</a> <a href="chap59.html">59</a> <a href="chap60.html">60</a> <a href="chap61.html">61</a> <a href="chap62.html">62</a> <a href="chap63.html">63</a> <a href="chap64.html">64</a> <a href="chap65.html">65</a> <a href="chap66.html">66</a> <a href="chap67.html">67</a> <a href="chap68.html">68</a> <a href="chap69.html">69</a> <a href="chap70.html">70</a> <a href="chap71.html">71</a> <a href="chap72.html">72</a> <a href="chap73.html">73</a> <a href="chap74.html">74</a> <a href="chap75.html">75</a> <a href="chap76.html">76</a> <a href="chap77.html">77</a> <a href="chap78.html">78</a> <a href="chap79.html">79</a> <a href="chap80.html">80</a> <a href="chap81.html">81</a> <a href="chap82.html">82</a> <a href="chap83.html">83</a> <a href="chap84.html">84</a> <a href="chap85.html">85</a> <a href="chap86.html">86</a> <a href="chap87.html">87</a> <a href="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
460
461 <hr />
462 <p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
463 </body>
464 </html>