<html><head><title>[ref] 8 Options Stack</title></head> <body text="#000000" bgcolor="#ffffff"> [<a href="../index.htm">Top</a>] [<a href = "chapters.htm">Up</a>] [<a href ="CHAP007.htm">Previous</a>] [<a href ="CHAP009.htm">Next</a>] [<a href = "theindex.htm">Index</a>] <h1>8 Options Stack</h1><p> <p> <font face="Gill Sans,Helvetica,Arial">GAP</font> Supports a global Options system. This is intended as a way for the user to provide guidance to various algorithms that might be used in a computation. Such guidance should not change mathematically the specification of the computation to be performed, although it may change the algorithm used. A typical example is the selection of a strategy for the Todd-Coxeter coset enumeration procedure. An example of something not suited to the options mechanism is the imposition of exponent laws in the <i>p</i>-Quotient algorithm. <p> The basis of this system is a global stack of records. All the entries of each record are thought of as options settings, and the effective setting of an option is given by the topmost record in which the relevant field is bound. <p> The reason for the choice of a stack is the intended pattern of use: <p> <pre> PushOptions( rec( <stuff> ) ); DoSomething( <args> ); PopOptions(); </pre> <p> This can be abbreviated, to <code>DoSomething( </code><var>args</var><code> : </code><var>stuff</var><code> );</code> with a small additional abbreviation of <var>stuff</var> permitted. See <a href="../ref/CHAP004.htm#SSEC010.2">function call!with options</a> for details. The full form can be used where the same options are to run across several calls, or where the <code>DoSomething</code> procedure is actually a binary operation, or other function with special syntax. <p> At some time, an options predicate or something of the kind may be added to method selection. <p> An alternative to this system is the use of additional optional arguments in procedure calls. This is not felt to be adequate because many procedure calls might cause, for example, a coset enumeration and each would need to make provision for the possibility of extra arguments. In this system the options are pushed when the user-level procedure is called, and remain in effect (unless altered) for all procedures called by it. <p> <a name = ""></a> <li><code>PushOptions( </code><var>options record</var><code> ) F</code> <p> This function pushes a record of options onto the global option stack. Note that <code>PushOption(rec(</code><var>opt</var><code> := fail))</code> has the effect of resetting option <var>opt</var>, since an option that has never been set has the value <code>fail</code> returned by <code>ValueOptions</code>. <p> Note that there is no check for misspelt or undefined options. <p> <a name = ""></a> <li><code>PopOptions( ) F</code> <p> This function removes the top-most options record from the options stack. <p> <a name = ""></a> <li><code>ResetOptionsStack( ) F</code> <p> unbinds (i.e. removes) all the options records from the options stack. <p> <strong>Note:</strong> <code>ResetOptionsStack</code> should <strong>not</strong> be used within a function. Its intended use is to clean up the options stack in the event that the user has <code>quit</code> from a <code>break</code> loop, so leaving a stack of no-longer-needed options (see <a href="CHAP006.htm#SSEC004.1">quit</a>). <p> <a name = ""></a> <li><code>ValueOption( </code><var>opt</var><code> ) F</code> <p> This function is the main method of accessing the Options Stack; <var>opt</var> should be the name of an option, i.e. a string. A function which makes decisions which might be affected by options should examine the result of <code>ValueOption( </code><var>opt</var><code> )</code>. If <var>opt</var> has never been set then <code>fail</code> is returned. <p> <a name = ""></a> <li><code>DisplayOptionsStack( ) F</code> <p> This function prints a human-readable display of the complete options stack. <p> <a name = ""></a> <li><code>InfoOptions V</code> <p> This info class can be used to enable messages about options being changed (level 1) or accessed (level 2). <p> The example below shows simple manipulation of the Options Stack, first using <code>PushOptions</code> and <code>PopOptions</code> and then using the special function calling syntax. <p> <pre> gap> foo := function() > Print("myopt1 = ", ValueOption("myopt1"), > " myopt2 = ",ValueOption("myopt2"),"\n"); > end; function( ) ... end gap> foo(); myopt1 = fail myopt2 = fail gap> PushOptions(rec(myopt1 := 17)); gap> foo(); myopt1 = 17 myopt2 = fail gap> DisplayOptionsStack(); [ rec( myopt1 := 17 ) ] gap> PopOptions(); gap> foo(); myopt1 = fail myopt2 = fail gap> foo( : myopt1, myopt2 := [Z(3),"aardvark"]); myopt1 = true myopt2 = [ Z(3), "aardvark" ] gap> DisplayOptionsStack(); [ ] gap> </pre> <p> <p> [<a href="../index.htm">Top</a>] [<a href = "chapters.htm">Up</a>] [<a href ="CHAP007.htm">Previous</a>] [<a href ="CHAP009.htm">Next</a>] [<a href = "theindex.htm">Index</a>] <P> <font face="Gill Sans,Helvetica,Arial">GAP 4 manual<br>December 2008 </font></body></html>