/usr/share/gap/doc/ref/chap5.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 | <?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 5: Functions</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="chap5" 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="chap4.html">[Previous Chapter]</a> <a href="chap6.html">[Next Chapter]</a> </div>
<p id="mathjaxlink" class="pcenter"><a href="chap5_mj.html">[MathJax on]</a></p>
<p><a id="X86FA580F8055B274" name="X86FA580F8055B274"></a></p>
<div class="ChapSects"><a href="chap5.html#X86FA580F8055B274">5 <span class="Heading">Functions</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap5.html#X870553EF8605792F">5.1 <span class="Heading">Information about a function</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X79C3BDC4781FA0FD">5.1-1 NameFunction</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X877F03F77FD74C98">5.1-2 NumberArgumentsFunction</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X818BAB817A4FB346">5.1-3 NamesLocalVariablesFunction</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X80E108C57F90FAA3">5.1-4 FilenameFunc</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X7FF7643781D2C194">5.1-5 StartlineFunc</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X845A929B83D46E01">5.1-6 PageSource</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap5.html#X851B58408520700D">5.2 <span class="Heading">Calling a function with a list argument that is interpreted as
several arguments</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X7CF4DDB97D65AE52">5.2-1 CallFuncList</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap5.html#X7EB0A85F7D128BE0">5.3 <span class="Heading">Functions that do nothing</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X7DB422A2876CCC4D">5.3-1 ReturnTrue</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X7C131FB17D7518FC">5.3-2 ReturnFalse</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X7A0994DE7C258E55">5.3-3 ReturnFail</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X810325697BDEF899">5.3-4 IdFunc</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap5.html#X80FE39D27CE3DE1B">5.4 <span class="Heading">Function Types</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X85E40340806C2B8C">5.4-1 IsFunction</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X874C7C6D8650D648">5.4-2 IsOperation</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap5.html#X87838FE885A9AAF9">5.4-3 FunctionsFamily</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap5.html#X81F732457F7BC851">5.5 <span class="Heading">Naming Conventions</span></a>
</span>
</div>
</div>
<h3>5 <span class="Heading">Functions</span></h3>
<p>The section <a href="chap4.html#X815F71EA7BC0EB6F"><span class="RefLink">4.23</span></a> describes how to define a function. In this chapter we describe functions that give information about functions, and various utility functions used either when defining functions or calling functions.</p>
<p><a id="X870553EF8605792F" name="X870553EF8605792F"></a></p>
<h4>5.1 <span class="Heading">Information about a function</span></h4>
<p><a id="X79C3BDC4781FA0FD" name="X79C3BDC4781FA0FD"></a></p>
<h5>5.1-1 NameFunction</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NameFunction</code>( <var class="Arg">func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns the name of a function. For operations, this is the name used in their declaration. For functions, this is the variable name they were first assigned to. (For some internal functions, this might be a name <em>different</em> from the name that is documented.) If no such name exists, the string <code class="code">"unknown"</code> is returned.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">NameFunction(SylowSubgroup);</span>
"SylowSubgroup"
<span class="GAPprompt">gap></span> <span class="GAPinput">Blubberflutsch:=x->x;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">NameFunction(Blubberflutsch);</span>
"Blubberflutsch"
<span class="GAPprompt">gap></span> <span class="GAPinput">a:=Blubberflutsch;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">NameFunction(a);</span>
"Blubberflutsch"
<span class="GAPprompt">gap></span> <span class="GAPinput">NameFunction(x->x);</span>
"unknown"
<span class="GAPprompt">gap></span> <span class="GAPinput">NameFunction(NameFunction);</span>
"NameFunction"
</pre></div>
<p><a id="X877F03F77FD74C98" name="X877F03F77FD74C98"></a></p>
<h5>5.1-2 NumberArgumentsFunction</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NumberArgumentsFunction</code>( <var class="Arg">func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns the number of arguments the function <var class="Arg">func</var> accepts. For functions that use <code class="code">arg</code> to take a variable number of arguments, as well as for operations, -1 is returned. For attributes, 1 is returned.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">NumberArgumentsFunction(function(a,b,c,d,e,f,g,h,i,j,k)return 1;end);</span>
11
<span class="GAPprompt">gap></span> <span class="GAPinput">NumberArgumentsFunction(Size);</span>
1
<span class="GAPprompt">gap></span> <span class="GAPinput">NumberArgumentsFunction(IsCollsCollsElms);</span>
3
<span class="GAPprompt">gap></span> <span class="GAPinput">NumberArgumentsFunction(Sum);</span>
-1
</pre></div>
<p><a id="X818BAB817A4FB346" name="X818BAB817A4FB346"></a></p>
<h5>5.1-3 NamesLocalVariablesFunction</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NamesLocalVariablesFunction</code>( <var class="Arg">func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a mutable list of strings; the first entries are the names of the arguments of the function <var class="Arg">func</var>, in the same order as they were entered in the definition of <var class="Arg">func</var>, and the remaining ones are the local variables as given in the <code class="keyw">local</code> statement in <var class="Arg">func</var>. (The number of arguments can be computed with <code class="func">NumberArgumentsFunction</code> (<a href="chap5.html#X877F03F77FD74C98"><span class="RefLink">5.1-2</span></a>).)</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">NamesLocalVariablesFunction(function( a, b ) local c; return 1; end);</span>
[ "a", "b", "c" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">NamesLocalVariablesFunction(function( arg ) local a; return 1; end);</span>
[ "arg", "a" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">NamesLocalVariablesFunction( Size );</span>
fail
</pre></div>
<p><a id="X80E108C57F90FAA3" name="X80E108C57F90FAA3"></a></p>
<h5>5.1-4 FilenameFunc</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ FilenameFunc</code>( <var class="Arg">func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>For a function <var class="Arg">func</var>, <code class="func">FilenameFunc</code> returns either <code class="keyw">fail</code> or the absolute path of the file from which <var class="Arg">func</var> has been read. The return value <code class="keyw">fail</code> occurs if <var class="Arg">func</var> is a compiled function or an operation. For functions that have been entered interactively, the string <code class="code">"*stdin*"</code> is returned, see Section <a href="chap9.html#X85EC7D9087C481B0"><span class="RefLink">9.5</span></a>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">FilenameFunc( LEN_LIST ); # a kernel function</span>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">FilenameFunc( Size ); # an operation</span>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">FilenameFunc( x -> x^2 ); # an interactively entered function</span>
"*stdin*"
<span class="GAPprompt">gap></span> <span class="GAPinput">meth:= ApplicableMethod( Size, [ Group( () ) ] );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">FilenameFunc( meth );</span>
"... some path .../grpperm.gi"
</pre></div>
<p><a id="X7FF7643781D2C194" name="X7FF7643781D2C194"></a></p>
<h5>5.1-5 StartlineFunc</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StartlineFunc</code>( <var class="Arg">func</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">‣ EndlineFunc</code>( <var class="Arg">func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Let <var class="Arg">func</var> be a function. If <code class="func">FilenameFunc</code> (<a href="chap5.html#X80E108C57F90FAA3"><span class="RefLink">5.1-4</span></a>) returns <code class="keyw">fail</code> for <var class="Arg">func</var> then also <code class="func">StartlineFunc</code> returns <code class="keyw">fail</code>. If <code class="func">FilenameFunc</code> (<a href="chap5.html#X80E108C57F90FAA3"><span class="RefLink">5.1-4</span></a>) returns a filename for <var class="Arg">func</var> then <code class="func">StartlineFunc</code> returns the line number in this file where the definition of <var class="Arg">func</var> starts.</p>
<p><code class="func">EndlineFunc</code> behaves similarly and returns the line number in this file where the definition of <var class="Arg">func</var> ends.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">meth:= ApplicableMethod( Size, [ Group( () ) ] );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">FilenameFunc( meth );</span>
"... some path ... gap4r5/lib/grpperm.gi"
<span class="GAPprompt">gap></span> <span class="GAPinput">StartlineFunc( meth );</span>
487
<span class="GAPprompt">gap></span> <span class="GAPinput">EndlineFunc( meth );</span>
487
</pre></div>
<p><a id="X845A929B83D46E01" name="X845A929B83D46E01"></a></p>
<h5>5.1-6 PageSource</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PageSource</code>( <var class="Arg">func</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This shows the file containing the source code of the function or method <var class="Arg">func</var> in a pager (see <code class="func">Pager</code> (<a href="chap2.html#X7ED03E41792C3840"><span class="RefLink">2.4-1</span></a>)). The display starts at a line shortly before the code of <var class="Arg">func</var>.</p>
<p>This function works if <code class="code">FilenameFunc(<var class="Arg">func</var>)</code> returns the name of a proper file. In that case this filename and the position of the function definition are also printed. Otherwise the function indicates that the source is not available (for example this happens for functions which are implemented in the <strong class="pkg">GAP</strong> C-kernel).</p>
<p>Usage examples:<br /> <code class="code">met := ApplicableMethod(\^, [(1,2),2743527]); PageSource(met);</code><br /> <code class="code">PageSource(Combinations);</code><br /> <code class="code">ct:=CharacterTable(Group((1,2,3))); </code><br /> <code class="code">met := ApplicableMethod(Size,[ct]); PageSource(met); </code></p>
<p><a id="X851B58408520700D" name="X851B58408520700D"></a></p>
<h4>5.2 <span class="Heading">Calling a function with a list argument that is interpreted as
several arguments</span></h4>
<p><a id="X7CF4DDB97D65AE52" name="X7CF4DDB97D65AE52"></a></p>
<h5>5.2-1 CallFuncList</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CallFuncList</code>( <var class="Arg">func</var>, <var class="Arg">args</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>returns the result, when calling function <var class="Arg">func</var> with the arguments given in the list <var class="Arg">args</var>, i.e. <var class="Arg">args</var> is "unwrapped" so that <var class="Arg">args</var> appears as several arguments to <var class="Arg">func</var>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">CallFuncList(\+, [6, 7]);</span>
13
<span class="GAPprompt">gap></span> <span class="GAPinput">#is equivalent to:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">\+(6, 7);</span>
13
</pre></div>
<p>A more useful application of <code class="func">CallFuncList</code> is for a function <code class="code">g</code> that is called in the body of a function <code class="code">f</code> with (a sublist of) the arguments of <code class="code">f</code>, where <code class="code">f</code> has been defined with a single formal argument <code class="code">arg</code> (see <a href="chap4.html#X815F71EA7BC0EB6F"><span class="RefLink">4.23</span></a>), as in the following code fragment.</p>
<div class="example"><pre>
f := function ( arg )
CallFuncList(g, arg);
...
end;
</pre></div>
<p>In the body of <code class="code">f</code> the several arguments passed to <code class="code">f</code> become a list <code class="code">arg</code>. If <code class="code">g</code> were called instead via <code class="code">g( arg )</code> then <code class="code">g</code> would see a single list argument, so that <code class="code">g</code> would, in general, have to "unwrap" the passed list. The following (not particularly useful) example demonstrates both described possibilities for the call to <code class="code">g</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintNumberFromDigits := function ( arg )</span>
<span class="GAPprompt">></span> <span class="GAPinput"> CallFuncList( Print, arg );</span>
<span class="GAPprompt">></span> <span class="GAPinput"> Print( "\n" );</span>
<span class="GAPprompt">></span> <span class="GAPinput"> end;</span>
function( arg ) ... end
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintNumberFromDigits( 1, 9, 7, 3, 2 );</span>
19732
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintDigits := function ( arg )</span>
<span class="GAPprompt">></span> <span class="GAPinput"> Print( arg );</span>
<span class="GAPprompt">></span> <span class="GAPinput"> Print( "\n" );</span>
<span class="GAPprompt">></span> <span class="GAPinput"> end;</span>
function( arg ) ... end
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintDigits( 1, 9, 7, 3, 2 );</span>
[ 1, 9, 7, 3, 2 ]
</pre></div>
<p><a id="X7EB0A85F7D128BE0" name="X7EB0A85F7D128BE0"></a></p>
<h4>5.3 <span class="Heading">Functions that do nothing</span></h4>
<p>The following functions return fixed results (or just their own argument). They can be useful in places when the syntax requires a function, but actually no functionality is required. So <code class="func">ReturnTrue</code> (<a href="chap5.html#X7DB422A2876CCC4D"><span class="RefLink">5.3-1</span></a>) is often used as family predicate in <code class="func">InstallMethod</code> (<a href="chap78.html#X837EFDAB7BEF290B"><span class="RefLink">78.2-1</span></a>).</p>
<p><a id="X7DB422A2876CCC4D" name="X7DB422A2876CCC4D"></a></p>
<h5>5.3-1 ReturnTrue</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReturnTrue</code>( <var class="Arg">...</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function takes any number of arguments, and always returns <code class="keyw">true</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">f:=ReturnTrue; </span>
function( arg ) ... end
<span class="GAPprompt">gap></span> <span class="GAPinput">f(); </span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">f(42);</span>
true
</pre></div>
<p><a id="X7C131FB17D7518FC" name="X7C131FB17D7518FC"></a></p>
<h5>5.3-2 ReturnFalse</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReturnFalse</code>( <var class="Arg">...</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function takes any number of arguments, and always returns <code class="keyw">false</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">f:=ReturnFalse; </span>
function( arg ) ... end
<span class="GAPprompt">gap></span> <span class="GAPinput">f(); </span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">f("any_string");</span>
false
</pre></div>
<p><a id="X7A0994DE7C258E55" name="X7A0994DE7C258E55"></a></p>
<h5>5.3-3 ReturnFail</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReturnFail</code>( <var class="Arg">...</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function takes any number of arguments, and always returns <code class="keyw">fail</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">oops:=ReturnFail; </span>
function( arg ) ... end
<span class="GAPprompt">gap></span> <span class="GAPinput">oops(); </span>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">oops(-42); </span>
fail
</pre></div>
<p><a id="X810325697BDEF899" name="X810325697BDEF899"></a></p>
<h5>5.3-4 IdFunc</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IdFunc</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns <var class="Arg">obj</var>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">id:=IdFunc; </span>
function( object ) ... end
<span class="GAPprompt">gap></span> <span class="GAPinput">id(42); </span>
42
<span class="GAPprompt">gap></span> <span class="GAPinput">f:=id(SymmetricGroup(3)); </span>
Sym( [ 1 .. 3 ] )
<span class="GAPprompt">gap></span> <span class="GAPinput">s:=One(AutomorphismGroup(SymmetricGroup(3)));</span>
IdentityMapping( Sym( [ 1 .. 3 ] ) )
<span class="GAPprompt">gap></span> <span class="GAPinput">f=s;</span>
false
</pre></div>
<p><a id="X80FE39D27CE3DE1B" name="X80FE39D27CE3DE1B"></a></p>
<h4>5.4 <span class="Heading">Function Types</span></h4>
<p>Functions are <strong class="pkg">GAP</strong> objects and thus have categories and a family.</p>
<p><a id="X85E40340806C2B8C" name="X85E40340806C2B8C"></a></p>
<h5>5.4-1 IsFunction</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsFunction</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>is the category of functions.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IsFunction(x->x^2);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsFunction(Factorial);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">f:=One(AutomorphismGroup(SymmetricGroup(3)));</span>
IdentityMapping( Sym( [ 1 .. 3 ] ) )
<span class="GAPprompt">gap></span> <span class="GAPinput">IsFunction(f); </span>
false
</pre></div>
<p><a id="X874C7C6D8650D648" name="X874C7C6D8650D648"></a></p>
<h5>5.4-2 IsOperation</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsOperation</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>is the category of operations. Every operation is a function, but not vice versa.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">MinimalPolynomial; </span>
<Operation "MinimalPolynomial">
<span class="GAPprompt">gap></span> <span class="GAPinput">IsOperation(MinimalPolynomial);</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsFunction(MinimalPolynomial); </span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">Factorial;</span>
function( n ) ... end
<span class="GAPprompt">gap></span> <span class="GAPinput">IsOperation(Factorial);</span>
false
</pre></div>
<p><a id="X87838FE885A9AAF9" name="X87838FE885A9AAF9"></a></p>
<h5>5.4-3 FunctionsFamily</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ FunctionsFamily</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>is the family of all functions.</p>
<p><a id="X81F732457F7BC851" name="X81F732457F7BC851"></a></p>
<h4>5.5 <span class="Heading">Naming Conventions</span></h4>
<p>The way functions are named in <strong class="pkg">GAP</strong> might help to memorize or even guess names of library functions.</p>
<p>If a variable name consists of several words then the first letter of each word is capitalized.</p>
<p>If the first part of the name of a function is a verb then the function may modify its argument(s) but does not return anything, for example <code class="func">Append</code> (<a href="chap21.html#X79E31DB27C82D6E1"><span class="RefLink">21.4-5</span></a>) appends the list given as second argument to the list given as first argument. Otherwise the function returns an object without changing the arguments, for example <code class="func">Concatenation</code> (<a href="chap21.html#X840C55A77D1BB2E1"><span class="RefLink">21.20-1</span></a>) returns the concatenation of the lists given as arguments.</p>
<p>If the name of a function contains the word "<code class="code">Of</code>" then the return value is thought of as information deduced from the arguments. Usually such functions are attributes (see <a href="chap13.html#X7C701DBF7BAE649A"><span class="RefLink">13.5</span></a>). Examples are <code class="func">GeneratorsOfGroup</code> (<a href="chap39.html#X79C44528864044C5"><span class="RefLink">39.2-4</span></a>), which returns a list of generators for the group entered as argument, or <code class="func">DiagonalOfMat</code> (<a href="chap24.html#X82B6B0298179D895"><span class="RefLink">24.12-1</span></a>).</p>
<p>For the setter and tester functions of an attribute <code class="code">Attr</code> the names <code class="code">SetAttr</code> resp. <code class="code">HasAttr</code> are available (see <a href="chap13.html#X7C701DBF7BAE649A"><span class="RefLink">13.5</span></a>).</p>
<p>If the name of a function contains the word "<code class="code">By</code>" then the return value is thought of as built in a certain way from the parts given as arguments. For example, creating a group as a factor group of a given group by a normal subgroup can be done by taking the image of <code class="func">NaturalHomomorphismByNormalSubgroup</code> (<a href="chap39.html#X80FC390C7F38A13F"><span class="RefLink">39.18-1</span></a>). Other examples of "<code class="code">By</code>" functions are <code class="func">GroupHomomorphismByImages</code> (<a href="chap40.html#X7F348F497C813BE0"><span class="RefLink">40.1-1</span></a>) and <code class="func">LaurentPolynomialByCoefficients</code> (<a href="chap66.html#X8467263B7EFA013E"><span class="RefLink">66.13-1</span></a>).</p>
<p>Often such functions construct an algebraic structure given by its generators (for example, <code class="func">RingByGenerators</code> (<a href="chap56.html#X7D736E027DFD8961"><span class="RefLink">56.1-4</span></a>)). In some cases, "<code class="code">By</code>" may be replaced by "<code class="code">With</code>" (like e.g. <code class="func">GroupWithGenerators</code> (<a href="chap39.html#X8589EF9C7B658B94"><span class="RefLink">39.2-3</span></a>)) or even both versions of the name may be used. The difference between <code class="code">StructByGenerators</code> and <code class="code">StructWithGenerators</code> is that the latter guarantees that the <code class="code">GeneratorsOfStruct</code> value of the result is equal to the given set of generators (see <a href="chap31.html#X82039A218274826F"><span class="RefLink">31.3</span></a>).</p>
<p>If the name of a function has the form "<code class="code">AsSomething</code>" then the return value is an object (usually a collection which has the same family of elements), which may, for example:</p>
<ul>
<li><p>know more about its own structure (and so support more operations) than its input (e.g. if the elements of the collection form a group, then this group can be constructed using <code class="func">AsGroup</code> (<a href="chap39.html#X7A0747F17B50D967"><span class="RefLink">39.2-5</span></a>));</p>
</li>
<li><p>discard its additional structure (e.g. <code class="func">AsList</code> (<a href="chap30.html#X8289FCCC8274C89D"><span class="RefLink">30.3-8</span></a>) applied to a group will return a list of its elements);</p>
</li>
<li><p>contain all elements of the original object without duplicates (like e.g. <code class="func">AsSet</code> (<a href="chap30.html#X856D927378C33548"><span class="RefLink">30.3-10</span></a>) does if its argument is a list of elements from the same family);</p>
</li>
<li><p>remain unchanged (like e.g. <code class="func">AsSemigroup</code> (<a href="chap51.html#X80ED104F85AE5134"><span class="RefLink">51.1-5</span></a>) does if its argument is a group).</p>
</li>
</ul>
<p>If <code class="code">Something</code> and the argument of <code class="code">AsSomething</code> are domains, some further rules apply as explained in <a href="../../doc/tut/chap7.html#X7EA77DE17DD8A231"><span class="RefLink">Tutorial: Changing the Structure</span></a>.</p>
<p>If the name of a function <code class="code">fun1</code> ends with "<code class="code">NC</code>" then there is another function <code class="code">fun2</code> with the same name except that the <code class="code">NC</code> is missing. <code class="code">NC</code> stands for "no check". When <code class="code">fun2</code> is called then it checks whether its arguments are valid, and if so then it calls <code class="code">fun1</code>. The functions <code class="func">SubgroupNC</code> (<a href="chap39.html#X7C82AA387A42DCA0"><span class="RefLink">39.3-1</span></a>) and <code class="func">Subgroup</code> (<a href="chap39.html#X7C82AA387A42DCA0"><span class="RefLink">39.3-1</span></a>) are a typical example.</p>
<p>The idea is that the possibly time consuming check of the arguments can be omitted if one is sure that they are unnecessary. For example, if an algorithm produces generators of the derived subgroup of a group then it is guaranteed that they lie in the original group; <code class="func">Subgroup</code> (<a href="chap39.html#X7C82AA387A42DCA0"><span class="RefLink">39.3-1</span></a>) would check this, and <code class="func">SubgroupNC</code> (<a href="chap39.html#X7C82AA387A42DCA0"><span class="RefLink">39.3-1</span></a>) omits the check.</p>
<p>Needless to say, all these rules are not followed slavishly, for example there is one operation <code class="func">Zero</code> (<a href="chap31.html#X8040AC7A79FFC442"><span class="RefLink">31.10-3</span></a>) instead of two operations <code class="code">ZeroOfElement</code> and <code class="code">ZeroOfAdditiveGroup</code>.</p>
<div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap4.html">[Previous Chapter]</a> <a href="chap6.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>
|