/usr/share/gap/doc/ref/chap29.html is in gap-doc 4r6p5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>GAP (ref) - Chapter 29: Records</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap29" onload="jscontent()">
<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>
<div class="chlinkprevnexttop"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap28.html">[Previous Chapter]</a> <a href="chap30.html">[Next Chapter]</a> </div>
<p id="mathjaxlink" class="pcenter"><a href="chap29_mj.html">[MathJax on]</a></p>
<p><a id="X7AA1073C7E943DD7" name="X7AA1073C7E943DD7"></a></p>
<div class="ChapSects"><a href="chap29.html#X7AA1073C7E943DD7">29 <span class="Heading">Records</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap29.html#X864F92347B5A3FF0">29.1 <span class="Heading">IsRecord and RecNames</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap29.html#X782A998E7D9EC406">29.1-1 IsRecord</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap29.html#X837F1E1F866FB1A0">29.1-2 RecNames</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap29.html#X7EAAE25D7A17F778">29.2 <span class="Heading">Accessing Record Elements</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap29.html#X806DE3BD78742CA4">29.3 <span class="Heading">Record Assignment</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap29.html#X86BC2672803863FB">29.4 <span class="Heading">Identical Records</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap29.html#X83A7E6607B1D63BC">29.5 <span class="Heading">Comparisons of Records</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap29.html#X79BE8D0E829E7ACE">29.6 <span class="Heading">IsBound and Unbind for Records</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap29.html#X7A13E8F87CAAA0AF">29.6-1 IsBound</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap29.html#X7CA9AEFE7DB71604">29.6-2 Unbind</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap29.html#X784897E180815EDA">29.7 <span class="Heading">Record Access Operations</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap29.html#X87BF90FA7F7A3B1B">29.7-1 NameRNam</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap29.html#X78199B6B84A017B9">29.7-2 RNamObj</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap29.html#X7821AC097821AC09">29.7-3 \.</a></span>
</div></div>
</div>
<h3>29 <span class="Heading">Records</span></h3>
<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>
<p>Record literals are written by writing down the components in order between "<code class="code">rec(</code>" and "<code class="code">)</code>", and separating them by commas "<code class="code">,</code>". Each component consists of the name, the assignment operator "<code class="code">:=</code>", and the value. The <em>empty record</em>, i.e., the record with no components, is written as <code class="code">rec()</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( a := 1, b := "2" ); # a record with two components</span>
rec( a := 1, b := "2" )
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( a := 1, b := rec( c := 2 ) ); # record may contain records</span>
rec( a := 1, b := rec( c := 2 ) )
</pre></div>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Display( last );</span>
rec(
a := 1,
b := rec(
c := 2 ) )
</pre></div>
<p>Records usually contain elements of various types, i.e., they are usually not homogeneous like lists.</p>
<p><a id="X864F92347B5A3FF0" name="X864F92347B5A3FF0"></a></p>
<h4>29.1 <span class="Heading">IsRecord and RecNames</span></h4>
<p><a id="X782A998E7D9EC406" name="X782A998E7D9EC406"></a></p>
<h5>29.1-1 IsRecord</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsRecord</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsRecordCollection</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsRecordCollColl</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRecord( rec( a := 1, b := 2 ) );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsRecord( IsRecord );</span>
false
</pre></div>
<p><a id="X837F1E1F866FB1A0" name="X837F1E1F866FB1A0"></a></p>
<h5>29.1-2 RecNames</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RecNames</code>( <var class="Arg">record</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>returns a list of strings corresponding to the names of the record components of the record <var class="Arg">record</var>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Set(RecNames( r )); # 'Set' because ordering depends on GAP session</span>
[ "a", "b" ]
</pre></div>
<p>Note that you cannot use the string result in the ordinary way to access or change a record component. You can use the <code class="code"><var class="Arg">record</var>.(<var class="Arg">name</var>)</code> construct for that, see <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>
<p><a id="X7EAAE25D7A17F778" name="X7EAAE25D7A17F778"></a></p>
<h4>29.2 <span class="Heading">Accessing Record Elements</span></h4>
<p><code class="code"><var class="Arg">r</var>.<var class="Arg">name</var></code></p>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">r.a;</span>
1
<span class="GAPprompt">gap></span> <span class="GAPinput">r.b;</span>
2
</pre></div>
<p><code class="code"><var class="Arg">r</var>.(<var class="Arg">name</var>)</code></p>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">old := rec( a := 1, b := 2 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">new := rec();</span>
rec( )
<span class="GAPprompt">gap></span> <span class="GAPinput">for i in RecNames( old ) do</span>
<span class="GAPprompt">></span> <span class="GAPinput"> new.(i) := old.(i);</span>
<span class="GAPprompt">></span> <span class="GAPinput">od;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Display( new );</span>
rec(
a := 1,
b := 2 )
</pre></div>
<p><a id="X806DE3BD78742CA4" name="X806DE3BD78742CA4"></a></p>
<h4>29.3 <span class="Heading">Record Assignment</span></h4>
<p><code class="code"><var class="Arg">r</var>.<var class="Arg">name</var> := <var class="Arg">obj</var></code></p>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">r.a := 10;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Display( r );</span>
rec(
a := 10,
b := 2 )
<span class="GAPprompt">gap></span> <span class="GAPinput">r.c := 3;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Display( r );</span>
rec(
a := 10,
b := 2,
c := 3 )
</pre></div>
<p>Note that assigning to a record changes the record.</p>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsBound(r.a);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsBound(r.d);</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">Unbind(r.b);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Display( r );</span>
rec(
a := 10,
c := 3 )
</pre></div>
<p><code class="code"><var class="Arg">r</var>.(<var class="Arg">name</var>) := <var class="Arg">obj</var></code></p>
<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>
<p><a id="X86BC2672803863FB" name="X86BC2672803863FB"></a></p>
<h4>29.4 <span class="Heading">Identical Records</span></h4>
<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>
<div class="example"><pre>
r := rec( a := 1 );
r := rec( a := 1, b := 2 );
</pre></div>
<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>
<div class="example"><pre>
r := rec( a := 1 );
r.b := 2;
</pre></div>
<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>
<div class="example"><pre>
r1 := rec( a := 1 );
r2 := r1;
r1 := rec( a := 1, b := 2 );
</pre></div>
<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>
<div class="example"><pre>
r1 := rec( a := 1 );
r2 := r1;
r1.b := 2;
</pre></div>
<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>
<p>Let us now consider under which circumstances two records are identical.</p>
<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>
<div class="example"><pre>
r1 := rec( a := 1 );
r2 := rec( a := 1 );
</pre></div>
<p>Also in the following example, no records in the list <code class="code">l</code> are identical.</p>
<div class="example"><pre>
l := [];
for i in [1..10] do
l[i] := rec( a := 1 );
od;
</pre></div>
<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>
<div class="example"><pre>
r1 := rec( a := 1 );
r2 := r1;
</pre></div>
<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>
<div class="example"><pre>
r1 := rec( a := 1 );
f := function ( r ) return r; end;
r2 := f( r1 );
</pre></div>
<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>
<div class="example"><pre>
r1 := rec( a := 1 );
r2 := ShallowCopy( r1 );
</pre></div>
<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>
<div class="example"><pre>
r1 := rec( a := 1 );
r2 := r1;
r1.b := 2;
</pre></div>
<p><a id="X83A7E6607B1D63BC" name="X83A7E6607B1D63BC"></a></p>
<h4>29.5 <span class="Heading">Comparisons of Records</span></h4>
<p><code class="code"><var class="Arg">rec1</var> = <var class="Arg">rec2</var></code></p>
<p><code class="code"><var class="Arg">rec1</var> <> <var class="Arg">rec2</var></code></p>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( a := 1, b := 2 ) = rec( b := 2, a := 1 );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( a := 1, b := 2 ) = rec( a := 2, b := 1 );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( a := 1 ) = rec( a := 1, b := 2 );</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( a := 1 ) = 1;</span>
false
</pre></div>
<p><code class="code"><var class="Arg">rec1</var> < <var class="Arg">rec2</var></code></p>
<p><code class="code"><var class="Arg">rec1</var> <= <var class="Arg">rec2</var></code></p>
<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> < <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> < <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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( axy := 1, bxy := 2 ) < rec( bxy := 2, axy := 1 ); # are equal</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( axy := 1 ) < rec( axy := 1, bxy := 2 ); # unbound is < 2</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput"># in new session the .axy components are compared first</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( axy := 1, bxy := 2 ) < rec( axy := 2, bxy := 0 ); # 1 < 2</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( axy := 1 ) < rec( axy := 0, bxy := 2 ); # 0 < 1</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">rec( bxy := 1 ) < rec( bxy := 0, axy := 2 ); # unbound is < 2</span>
true
</pre></div>
<p><a id="X79BE8D0E829E7ACE" name="X79BE8D0E829E7ACE"></a></p>
<h4>29.6 <span class="Heading">IsBound and Unbind for Records</span></h4>
<p><a id="X7A13E8F87CAAA0AF" name="X7A13E8F87CAAA0AF"></a></p>
<h5>29.6-1 IsBound</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsBound</code>( <var class="Arg">r.name</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsBound( r.a );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsBound( r.c );</span>
false
</pre></div>
<p><a id="X7CA9AEFE7DB71604" name="X7CA9AEFE7DB71604"></a></p>
<h5>29.6-2 Unbind</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Unbind</code>( <var class="Arg">r.name</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := rec( a := 1, b := 2 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Unbind( r.a ); r;</span>
rec( b := 2 )
<span class="GAPprompt">gap></span> <span class="GAPinput">Unbind( r.c ); r;</span>
rec( b := 2 )
</pre></div>
<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>
<p><a id="X784897E180815EDA" name="X784897E180815EDA"></a></p>
<h4>29.7 <span class="Heading">Record Access Operations</span></h4>
<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>
<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 functions to translate RNams to strings that give the component names and vice versa.</p>
<p><a id="X87BF90FA7F7A3B1B" name="X87BF90FA7F7A3B1B"></a></p>
<h5>29.7-1 NameRNam</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NameRNam</code>( <var class="Arg">nr</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a string representing the component name corresponding to the RNam <var class="Arg">nr</var>.</p>
<p><a id="X78199B6B84A017B9" name="X78199B6B84A017B9"></a></p>
<h5>29.7-2 RNamObj</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RNamObj</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RNamObj</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</td></tr></table></div>
<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>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">NameRNam(798);</span>
"BravaisSupergroups"
<span class="GAPprompt">gap></span> <span class="GAPinput">RNamObj("blubberflutsch");</span>
2075
<span class="GAPprompt">gap></span> <span class="GAPinput">NameRNam(last);</span>
"blubberflutsch"
</pre></div>
<p>The correspondence between strings and RNams is not predetermined ab initio, but RNams are assigned to component names dynamically on a "first come, first serve" 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>
<p><a id="X7821AC097821AC09" name="X7821AC097821AC09"></a></p>
<h5>29.7-3 \.</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ \.</code>( <var class="Arg">obj</var>, <var class="Arg">rnam</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsBound\.</code>( <var class="Arg">obj</var>, <var class="Arg">rnam</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ \.\:\=</code>( <var class="Arg">obj</var>, <var class="Arg">rnam</var>, <var class="Arg">val</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Unbind\.</code>( <var class="Arg">obj</var>, <var class="Arg">rnam</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<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>
<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>
<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>
<div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap28.html">[Previous Chapter]</a> <a href="chap30.html">[Next Chapter]</a> </div>
<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>
<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>
|