| products/Sources/formale Sprachen/GAP/pkg/utils/doc/chap8.html |
 |
<?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 (Utils) - Chapter 8: 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= "chap8" 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="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="chap7.html">[Previous Chapter]</a> <a href="chap9.html">[Next Chapter]</a> </div>
<p id="mathjaxlink" class="pcenter"><a href="chap8_mj.html">[MathJax on]</a></p>
<p><a id="X7AA1073C7E943DD7" name="X7AA1073C7E943DD7"></a></p>
<div class="ChapSects"><a href="chap8.html#X7AA1073C7E943DD7">8 <span class="Heading">Records</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap8.html#X82B3D1D583CDF0E5">8.1 <span class="Heading">Functions for records</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap8.html#X84D82EB579B2ACCD">8.1-1 AssignGlobals</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap8.html#X7E6207B47B9AA30C">8.2 <span class="Heading">Option records for functions</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap8.html#X8322B9377CC590D2">8.2-1 OptionRecordWithDefaults</a></span>
</div></div>
</div>
<h3>8 <span class="Heading">Records</span></h3>
<p><a id="X82B3D1D583CDF0E5" name="X82B3D1D583CDF0E5"></a></p>
<h4>8.1 <span class="Heading">Functions for records</span></h4>
<p><a id="X84D82EB579B2ACCD" name="X84D82EB579B2ACCD"></a></p>
<h5>8.1-1 AssignGlobals</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; AssignGlobals</code>( <var class="Arg">rec</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function has been transferred from package <strong class="pkg">RCWA</strong>.</p>
<p>It assigns the record components of <var class="Arg">rec</var> to global variables with the same names.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">r := rec( a := 1, b := 2, c := 3 );; </span>
<span class="GAPprompt">gap></span> <span class="GAPinput">AssignGlobals( r );</span>
The following global variables have been assigned:
[ "a", "b", "c" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">[a,b,c];</span>
[ 1, 2, 3 ]
</pre></div>
<p><a id="X7E6207B47B9AA30C" name="X7E6207B47B9AA30C"></a></p>
<h4>8.2 <span class="Heading">Option records for functions</span></h4>
<p><a id="X8322B9377CC590D2" name="X8322B9377CC590D2"></a></p>
<h5>8.2-1 OptionRecordWithDefaults</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; OptionRecordWithDefaults</code>( <var class="Arg">defaults</var>, <var class="Arg">useroptions</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This functions has been transferred by Chris Jefferson from other packages. It simplifies the handling of records which are intended to be used for expressing configuration options. <var class="Arg">defaults</var> represents the "default record", and <var class="Arg">useroptions</var> lets the user give new values for values in <var class="Arg">defaults</var>.</p>
<p>The function returns a record with the same component names as <var class="Arg">defaults</var> and which has the same values as <var class="Arg">defaults</var>, except for those component names in <var class="Arg">useroptions</var>, where the values in <var class="Arg">useroptions</var> are used instead. An error is given if <var class="Arg">useroptions</var> contains any component names not in <var class="Arg">defaults</var>. If <var class="Arg">useroptions</var> is an empty list it is treated as an empty record, and if <var class="Arg">useroptions</var> is a list of length <span class="SimpleMath">1</span> containing a record, this record is used as <var class="Arg">useroptions</var>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">defaults := rec( a := 1, b := 2, c := 3 );;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">OptionRecordWithDefaults( defaults, rec( a := 6) );</span>
rec( a := 6, b := 2, c := 3 )
<span class="GAPprompt">gap></span> <span class="GAPinput">OptionRecordWithDefaults( defaults, rec( b := 7, c := 8 ) );</span>
rec( a := 1, b := 7, c := 8 )
<span class="GAPprompt">gap></span> <span class="GAPinput">OptionRecordWithDefaults( defaults, [ ] );</span>
rec( a := 1, b := 2, c := 3 )
<span class="GAPprompt">gap></span> <span class="GAPinput">OptionRecordWithDefaults( defaults, [ rec( c := 8 ) ] );</span>
rec( a := 1, b := 2, c := 8 )
<span class="GAPprompt">gap></span> <span class="GAPinput">OptionRecordWithDefaults( defaults, rec( d := 9 ) );</span>
Error, Unknown option: d
<span class="GAPprompt">gap></span> <span class="GAPinput">OptionRecordWithDefaults( defaults, [ rec( b := 7 ), rec( c := 8 ) ] );</span>
Error, Too many arguments for function
<span class="GAPprompt">gap></span> <span class="GAPinput">OptionRecordWithDefaults( defaults, [6,7,8] );</span>
Error, Too many arguments for function
</pre></div>
<p>This function is designed to support functions with optional arguments given as a variable record, of the form <code class="code">function(x,y,options...)</code>. In the following, very contrived, example function, <code class="code">PrintDimensions</code>, the defaults are given by the variable <code class="code">order</code> which takes values <code class="code">h</code>, <code class="code">w</code> and <code class="code">d</code> having default values <span class="SimpleMath">1</span>, <span class="SimpleMath">2</span> and <span class="SimpleMath">3</span>. If there is a second argument, then <code class="code">OptionRecordWithDefaults( order, arg[2] );</code> is used to cvhange the values. These three values then determine the order in which the three dimensions are printed using a <code class="code">SortParallel</code> command.</p>
<div class="example"><pre>
PrintDimensions := function( arg )
local nargs, dim, order, V, L, len, K, i;
nargs := Length( arg );
dim := [ arg[1]!.height, arg[1]!.width, arg[1]!.depth ];
order := rec( h := 1, w := 2, d := 3 );
V := [ "height", "width", "depth" ];
if ( nargs > 1 ) and IsRecord( arg[2] ) then
order := OptionRecordWithDefaults( order, arg[2] );
fi;
L := [ order!.h, order!.w, order!.d ];
len := Length( L );
K := [ 1..len ];
SortParallel( L, K );
Print( "dimensions: " );
Print( V[K[1]], " = ", dim[K[1]], ", " );
Print( V[K[2]], " = ", dim[K[2]], ", " );
Print( V[K[3]], " = ", dim[K[3]], "\n" );
end;;
</pre></div>
<p>In the example below the first call to <code class="code">PrintDimensions</code> has just one parameter, <code class="code">mydim</code>, so the default order is used. In the second call, alternate values for <code class="code">h</code>, <code class="code">w</code> and <code class="code">d</code> are given, causing the width to be printed first, and then the depth and height.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">mydim := rec( height := 45, width := 31, depth := 17 ); </span>
rec( depth := 17, height := 45, width := 31 )
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintDimensions( mydim );</span>
dimensions: height = 45, width = 31, depth = 17
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintDimensions( mydim, rec( h:=3, w:=1, d:=2 ) );</span>
dimensions: width = 31, depth = 17, height = 45
</pre></div>
<div class="chlinkprevnextbot"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap7.html">[Previous Chapter]</a> <a href="chap9.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="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
<hr />
<p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-11-04)
¤
*© Formatika GbR, Deutschland
|
|