Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  chap8_mj.html   Sprache: HTML

 
 products/sources/formale Sprachen/GAP/pkg/utils/doc/chap8_mj.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>
<script type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<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_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chap8_mj.html">8</a>  <a href="chap9_mj.html">9</a>  <a href="chap10_mj.html">10</a>  <a href="chap11_mj.html">11</a>  <a href="chap12_mj.html">12</a>  <a href="chapBib_mj.html">Bib</a>  <a href="chapInd_mj.html">Ind</a>  </div>

<div class="chlinkprevnexttop"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap7_mj.html">[Previous Chapter]</a>    <a href="chap9_mj.html">[Next Chapter]</a>   </div>

<p id="mathjaxlink" class="pcenter"><a href="chap8.html">[MathJax off]</a></p>
<p><a id="X7AA1073C7E943DD7" name="X7AA1073C7E943DD7"></a></p>
<div class="ChapSects"><a href="chap8_mj.html#X7AA1073C7E943DD7">8 <span class="Heading">Records</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap8_mj.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_mj.html#X84D82EB579B2ACCD">8.1-1 AssignGlobals</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap8_mj.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_mj.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">‣ 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">‣ 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</codecommand.</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_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap7_mj.html">[Previous Chapter]</a>    <a href="chap9_mj.html">[Next Chapter]</a>   </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chap8_mj.html">8</a>  <a href="chap9_mj.html">9</a>  <a href="chap10_mj.html">10</a>  <a href="chap11_mj.html">11</a>  <a href="chap12_mj.html">12</a>  <a href="chapBib_mj.html">Bib</a>  <a href="chapInd_mj.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>

99%


¤ Dauer der Verarbeitung: 0.8 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge