<p>hischapter <strong=pkg"GAP<strong programming language.It ,inprinciple to predict resultof and .Inorderto about have tolookmore closely of interpretation thevariousrepresentations ofdata involved<p
this isand that not externalrepresentations according therules below, as. Those are called em</> of programminglanguage<p>
<p>The internal representation created by reading is called either an <em>expression</em> or a <em>statement</em>. Later we will distinguish between those two terms. However for now we will use them interchangeably. The exact form of the internal representation does not matter. It could be a string of characters equal to the<>
<p>After the input has been read it/><div
<p
<p>The process called>printing<em.It takesthe produced the and an external representationi.. astring of again you with thisexternal representation up you You look itpasteit with the mouse another window,or it a file<pjava.lang.StringIndexOutOfBoundsException: Index 322 out of bounds for length 322
<p>Lets look
<div="">pre 1 + 2 *<The internal representationcreated reading called an<em>expression</em> or a <em>statement</em>. Later we will distinguish between those two terms. Howeverfornow we will use interchangeably The form of theinternal representation not. Itcould a string characters to external, in case reading only to for. It beseries ofmachine instructions would appropriatelybecalled compilation Itis fact tree structure/
</></div
<p><strongjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<div class="example"><pre>
+
/ \ 1
\ 23
<
<p>Thisdiv class=examplepre>
<> this fashion we can predictthe of input weknow the syntactic that governtheprocess of readingand semantic that us every how value computed terms the of subexpressions.Thesyntactic are insections< href"hap4_mj.tmlX80A85A707B6F4BE7">span"efLink">4./pan>< href"chap4_mj.html#X7E90E6607F4E4943"><span class=RefLink.</pana,< href=chap4_mj.tmlX7C53CEFC8641B919< classRefLink.<span, < hrefchap4_mj.#X87506BDC7D5F789E">spanclass=RefLink">4.5</></a> and <a href".html#X860313A179A5163F"><span class"RefLink">4.6</span</> semantic rules aregivenin sections <a href="chap4_mj..html#X7BAFE9C1817253C6"><span class"RefLink">4.7<span<a> <a href"chap4_mj.html#X7A4C2D0E7E286B4F"<span class="RefLink>4.8<span</a, ahref"chap4_mjhtmlX78C70489791FDF43">spanclass"RefLink">.</pan></a>, a href="chap4_mj.htmlX7A274A1F8553B7E6"><span class="RefLink">4.13</span></a>, <a href="chap4_mj.html#X7B66C8707B5DE10A=RefLink">4.14</span</>, a href"chap4_mj.html#X8543285D87361BE6"<span class=RefLink">4.<span/> <a href="chap4_mj.html#X7E6A50307F4D3FAE"><span=RefLink151span> ahref.X825803DE78251DA6span classRefLink4.-2<span>/> <hrefhtml"<spanclass"">.-3/></, ="chap4_mj#X87AA46408783383F class=">4.-<span><a> < ="chap4_mj#X8295CBF47FAA05C9"> class="">.-//>a =".#X78783E777867638A class4.15-<span/a< ="chap4_mj.html#X815F71EA7BC0EB6F>< class=RefLink>4.11</><a,andthechaptersdescribingtheindividualdatatypes<p
<p>Most input of <strong class="pkg">GAP</strong> consists of sequences of thep>n thisfashion we can predictthe ofevery input when weknow syntactic rulesthat the the rules tell for everyexpression howits value iscomputed in terms of values thesubexpressions. The syntactic rules aregiveninsections <href=chap4_mj.#X80A85A707B6F4BE7"< class=RefLink"42<spana,< =".htmlX7E90E6607F4E4943><span ="">4.</span></> < ="chap4_mj#X7C53CEFC8641B919>span="4.4/></> < ="chap4_mj#X87506BDC7D5F789E>span=RefLink45/spana,andahrefchap4_mj.tml#X860313A179A5163F"< class=""4.6</>/> semantic rulesaregiven .#">< class"">.7<span<a,< ="chap4_mjhtmlX7A4C2D0E7E286B4F"><span="">4.<spana,< href=chap4_mj#X78C70489791FDF43< ="">4</pana>< href=chap4_mj.html#X7A274A1F8553B7E6><panclassRefLink.<spana,< =chap4_mj.#X7B66C8707B5DE10A>spanclassRefLink>.14</span>/a>,<hrefchap4_mj#X8543285D87361BE6"<span class="RefLink"415/></a,<a="chap4_mjX7E6A50307F4D3FAEspan=">151span></> <aa href="chap4_mjhtmlX825803DE78251DA6"<spanclass=RefLink"4152>/ a ="chap4_mj.htmlX875000188622700D"<span=RefLink.-3/span</> a href="chap4_mj.html#>spanclass=="RefLink>.15-</span</>, < href"hap4_mj#X8295CBF47FAA05C9><panclass"RefLink"4.-<span/a>< =.html#">< classRefLink>156spana,<a href.#F71EA7BC0EB6F<span ="RefLink>411<span></> andandthechaptersdescribing individual data ./>
<p>Digits, uppercase and lowercase letters, <strong class="button">Space</strong>, <strong class="button">Tab</strong>, <strong class="button">Newline</strong>, <strong class="button">Return</strong> and the special characters</p>
<p>The process of reading, i.e., of assembling the input into ()*+ #
<p>A <em>keyword</em> is }
<p>Operator
<>. <span class="eading>Symbols</span<h4
+ java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
> gt!
:= . .. -> , ; [
] { } :
</pre></div>
<p>Note
<p><a divclass="example"<>
<h4>4. &t;> < <= > >= ![
<p>The{} () :
<p>A <em>comment</em> starts with the character <code class="code">#</code>, which is sometimes called sharp or hatch, and continues to the <pre>/div
<p>For example, the following statement</p>
<div class="example"><pre">Whitespaces/></h4>
iflt0 then a:ielse=ifi
</pre></div>
<p>is equivalent to</p>
<div class="example
f i
:;# takeadditivejava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
else
=i takeitself
fi pre
<p>a: ;# itself
</re/>
ifi<0thena:p>which the shows it possible write comments the statementis<emnot<em top>
</pre></div>
<psince the <code class=keywif<code beseparated from the identifier< class"i/ode a whitespace and similarly <code class"">then/> and <codeclass"code>/code, codeclass">else<code <code ="code><> must.</>
<p><a java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<h4p>emNote</em>: Several tokensfrom the list of keywords above appear tobe identifiersrepresenting functions literals various but actually as for reasonsTheonly of thisisthat those identifierscannot bere-ssigned,and donot have objects to, which be to variablesorpassed functions.These <codeclass"">true>,< classkeywfalse/> < class"></code (ahref"chap7_mjX830E443284780FB9< classRefLink.53/></a),<ode class=">IsBound<code> (a ="chap4_mj#X842B89D4860FD5DB"< class=RefLink">4.-/></>, < class"Unbind/code> (a href=chap4_mj.html#X7BABB3E77F52626C"< =RefLink8-</>/>) code classfunc"Info/> (<ahref="chap7_mjhtml">< class=RefLink>.-<span</>)and< class"func><> < href.htmlX7EED949B83046A7F>span=RefLink78.-<span>a)</>
<p>An <em>identifier</em> is used to refer to a variable (see <a href="chap4_mj.html#X7A4C2D0E7E286B4F"><span class="RefLink">4.8</span></a>). An identifier usually consists of letters, digits, underscores <code class="code">_</code>, and <q>at</q>-characters <code class="code">@</code>, and must contain at least one non-digit. An identifier is terminated by the first character not in this class. Note that the <q>at</java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<
<div class="example"><pre>
a foo
ello HELLO
x100 100x _100pAn>identifier</m> isused to toa variable ( <a href=chap4_mj.html#X7A4C2D0E7E286B4F"><spanclass=RefLink>4.8<span</a>.An identifierusually consists of letters, digits, underscores <odeclass"ode<code,and<>t<q-characters < classcode"></ode>, and must containat least one non-digit. An identifier isterminatedbythe first character not in this class. Notethat the <>at</q>character <code class="code@/code isto namespaces ahref.htmlX7DF8774F7D542298">spanclass="RefLink.</>/>for<pjava.lang.StringIndexOutOfBoundsException: Index 603 out of bounds for length 603
some_people_prefer_underscores_to_separate_wordsHello
WePreferMixedCaseToSeparateWords
abc
</presome_people_prefer_underscores_to_separate_words
<p>Note@def
<p>The
<div class
G<> backslashcodeclass=code"\/> can be used to include other characters identifiers;abackslash followed a characterisequivalent to character, except that thisescape sequence is considered to be anordinaryletter. For example</p>
</(\,5)
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; IsValidIdentifier</code>( <var class="Arg
g <varclass="Arg">str> would a valididentifier of, digits underscores;otherwiseit returns < class=keyw</code. It doesnot whether < class"">str>containsescaped backslashcode=code></code>/>
<p>Note that the <q>at</q>-character is used to implement namespaces for global variables in packages. See <a href="chap4_mj.html#X7DF8774F7D542298"><span class="RefLink">4.10</span></a> for details.</p>
<h5>4.6-2 <span class="Heading">Conventions about Identifiers</span></h5>
<p>(The following rule is stated also in Section <a href="../../doc/tut/chap2_mj<
<p>The name of almost every global variable
<p>For example, valid classpkg</strong which some variables names withcapital lettersmay runinto errors a newer versionof classpkg</strongor in a <strong class="pkg"></strong withmoreor packagesbecauseitmay that variablesarepredefined variables this.</>
<h4>4.7 <span class="Heading">Expressions<>The nameof every global in thestrong="pkg">GAP</strong library and instrong="pkg">GAP</strong> packagesstarts with a <em>capital letter</em>. (See Section <a href"chap6_mj.html##X81667F568237B232"><spanclass"RefLink">6.1</span</> for thefew.) For variables, we only choosing names that start a <em>lower letter</em>,in to avoid nameclashes/p>
<p>An <em>expression</em> is a construct that evaluates to a value. Syntactic constructs that are executed to produce a side effect and return no value are called <em>statements</em> (see <a href="chap4_mj.html#X8543285D87361BE6"><span class="RefLink">4.15</span></a>). Expressions appear as right hand sides of assignments (see <a href="chap4_mj.html#X7E6A50307F4D3FAE"><span class=
<p>Note that an expression is not the same as a value. For
</li/>
<><pintegerliterals( Chapterahref=chap14_mj#X853DF11B80068ED5< classRefLink>4<span<a)<pjava.lang.StringIndexOutOfBoundsException: Index 121 out of bounds for length 121
</li><p> point (seeChapterhref.#AA901181CA568F class"/><>,/>
<li><p>permutation literals (see Chapter <a href="chap42_mj.html#X80F808307A2D5AB8"><span class="RefLink">42</span><lip> literalssee Chapter a href".html#X80F808307A2D5AB8"<spanclass=RefLink"42/span<a>)/>
</li>
<li><p>string
<
<li
<li
<li><p>list literalsli
</li>
<li<>ecord (see <a href=chap29_mjX7AA1073C7E943DD7< classRefLink<span></a)</
</li>
</ul, for the expressions abovecanbe combined the to more expressionsOf course those expressions canthen combined with operatorsto form evenmore complexexpressionsTheem>operators</em fall three classesTheem>comparisonsem are <codeclasscode">=</ode>, <code class="code">&t;></ode>, <code class="code">&;</code>, < class="code">lt;=</code>,<code class=code"></code>, <code class="code">>=/code> and <code class="keyw">in<code>(seea hrefchap4_mjhtmlX7A274A1F8553B7E6">< class=RefLink"4.13</</span>/a> and<a hrefchap30_mjhtmlX82D39CF980FDBFFA"><span class="RefLink>30.6</pan<a) The> operatorsemarecode class">+</>,<codeclass=code>-</code,< class="code>*/odecode class"><code,< class="keyw<code,andcodeclass">^/> ( <a ="chap4_mj#X7B66C8707B5DE10A< =RefLink.<span/a). The <em>logical operators/> <codeclass">not/>,<code class"keyw>/> codeclasskeyw"or/>( a href=chap20_mjhtml#X79AD41A185FD7213">spanclass"">204/></>.<pjava.lang.StringIndexOutOfBoundsException: Index 1254 out of bounds for length 1254
<p>Expressions, for="">-to<td
<pThe example a verysimple value4 a more expression/>
<div class="tdleft"><m>comparison(ee a ="chap4_mj.html#X7A274A1F8553B7E6">span="">413<span><a)/m>/>
<>
<td class="tdleft"><em>operator</em
<td class="tdleft"><em>associativity</em></td>
</td ="tdleft> <ode class=code"=/>,<code=code>lt;</code>,<codeclass"ode><</code;</code> <code class"code>lt=/code>, <code classcode">&t;</ode>,<code class=code">>=</ode and <code class="">in</code><td
<tr>
<td="tdleft>em>rithmetic (see ahref"chap4_mjX7B66C8707B5DE10A><span="RefLink">414/></a)/></td
<td class="tdlefttdclass"tdleft">/td>
</tr>
<tr>
< class"> <code class"code"^</ode</djava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
<td class="tdleft">none</td>
</tr>
<tr
<td class="tdleft"> unary <code class="code">+</tdclass"tdleft"">left-to-right</td>
<td classtdleftright-toleft</d
</tr>
<tr
<td class">eftto-ight<td>
<td class="tdleft">left>
</tr><br >
<>
<td
<tdclass="">left-right>
</tr>
<trh4>4.8< class"">Variables></h4java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51
<td class=tdleftemcomparisonsee href.htmlX7A274A1F8553B7E6">span class="RefLink"413</pan></a></m>/td>
<td class="tdleft"></td>
</tr>
<
<td class="tdleft"> <code is class <em>arguments/m>of. They similarly to variables, except theyare bound to the ofthe actual upon function call ( <a hrefchap4_mj#X78C70489791FDF43< class="RefLink">4.12<span/>./p>
<td class="tdleft">none</td>
</tr>
<tr>
<td class="tdleft"><em>logical (see <a href="chap20_mj.html#X79AD41A185FD7213"><span class="RefLink">20.4</span></a<p>Eachvariable has a name thatis alsocalled its <em>dentifier</em. This is because in a given scope an identifier identifies unique variable (see <a href"chap4_mj.html#X860313A179A5163F">span="RefLink">4.6<span/>) A<em>scope/m>is lexical of a program textThere the<em>global scope</em> enclosesthe entire text there local that from < classkeywfunction<code keyword,denotingthebeginning a function, tothecorresponding <codecode class"><code . A<>localscope/em variables, identifiersaregiven in formal list and the< =keyw></>declarationofthefunction see< =chap4_mj.html#X815F71EA7BC0EB6F">< classRefLink411/span>a) Usage an in text to variable the scope has identifier its. this from identifiers tovariables done the is , not it executed<trongclass=pkgstrongsaidem scoping.Theexample onerefersdifferentatpointsthe./>
<td class="tdleftend;
</tr>
<tr>
<tdclass"tdleft> code class="">not/><td>
<td
</tr>
<tr>
<td class="tdleft"> <code class="keyw">and</code></td>
<td class="tdleft">left-to-right</td>
/>
<java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
< classclassor/
<td class="tdleft">left-to-right</td>
<>
</table>4- IsBound>
</div>
<p< ="X7A4C2D0E7E286B4Fname"">a<p>
<h44. < classHeading</span<h4
<p>
<p>Initially an ordinary variable is not bound>482 Unbind/5>
<p>A pdeletesthe < class"">ident>.If thereisno othervariable pointing thesamevalue <varclass=Arg</var, this will removed the garbage. Therefore<codeclass"Unbind/>can ridof unwantedlarge objects<p
<p>Each variablehasa thatis called itsemidentifier</em>.This isbecause a givenscope an identifies unique (see<a hrefchap4_mj#X860313A179A5163F< class="RefLink>.6<span</>)A><em> is a lexicalpart programtext There is the<em <em> enclosestheentire text,andthere arelocalscopesthat from the<code class="keywfunctioncode keyword,denoting the offunction, tocorresponding<code class class=keyw"end</ode> keyword A <em>ocal scope</em> introduces new variables, whoseidentifiersare givenin the formal argument list and the <code class"keyw></> declaration thefunction(seea href"hap4_mjhtml#815F71EA7BC0EB6F""><spanclass"RefLink">4.11</></a>).Usage an identifierin a program text refers to thevariable in the innermost that has this identifier as its name Because this mapping fromidentifiers to variables isdonewhen the programis read, not when it is executed, < class="">GAP/strong said to have <m>exical scoping</> following example showshowoneidentifierrefers to variables at differentpointsin the program text<p
<div class="example"><> vastmajority of <strong="pkg">GAP</> aredefinedat the outerlevel(he global). They areused toaccessand objects either the class"kg>GAP</strong> libraryorpackages or in user' code.<p>
g := 0; # global variable g
x : ( a,b c)
local y;
g := c; # c refers to argument c of functionCertain special areprovidedformanipulating variables are available other ofvariable such localvariables or arguments.pjava.lang.StringIndexOutOfBoundsException: Index 181 out of bounds for length 181
= )
local d, e, f;
d := y; # y refers to argument y of function y
e := b; # b refers to argument b of function x
f := g; # g refers to global variable div class="example"><pre>
return d + e + f;
end
return y( a ); # y refers to span="GAPprompt">><spanspan="GAPinput">globalb : truespan>
end
</pre></div>
<p>It is important class"gapgt</span> <spanclass""f :function)<>
<p>In those languages a variable denotes a block of memory. The value of the variable is <span="GAPprompt">gt<> <spanclassGAPinput>returnglobali + 1<span
<p>In <strong class="pkg">GAP</strong> on the ="GAPprompt"&; span">return 2;<span
<a="X842B89D4860FD5DB" name">/a<p>
<h5>4.8-1 IsBound 3 +1;
<div class="func"><table class="func"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<p<codeclass"IsBound</code <code ="keywtrue> the< class">ident<var to avalue,and <code class"">false</> otherwise.</p>
<p>For records and lists <p> thatthefunctions class=func</code < ="chap4_mj.html#X876A6EB68745A510">span="RefLink">.-</></a>),< ="func">NamesSystemGVars><ahrefchap4_mjhtml#X7E604AF579A7BC92>span="49-10/>/>,and code =func></> ( ="hap4_mjhtmlX870169447AF490D8>spanclass">4.-11<span<a),deal with the<em>global namespace</em><p>
<p><a id="><id"X7CD3523B84744EB2 name"><a><pjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
<h5>4.8-2 Unbind
<div class="func"><table =keywcodeif global bystring class</var read and ="">false otherwise default
<p>deletes"CE44478254F27=X850CE44478254F27/a/java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
<h4>4.9 <span class="java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<p>The vast h5>4.3MakeReadWriteGlobal<h5>
<p>Note that for packages
<in special facilitiesare provided for global which not for other types variable as variablesor function arguments).</pjava.lang.StringIndexOutOfBoundsException: Index 181 out of bounds for length 181
<p>First
<span class="GAPprompt">gap>17
< class>>/> <spanclass"">globalbtrue;/span
<span class="GAPprompt">gap
<pan="GAPprompt>>span span class=""(globalb/>
<span class="GAPprompt"gap;/spanspan""MakeReadOnlyGlobalxx"</pan>
<spanclass">&;/>< ="APinput> :16<span
<ss"APprompt"&;/> <span="GAPinput"> return globali+1;/spanjava.lang.StringIndexOutOfBoundsException: Index 93 out of bounds for length 93
<span="GAPprompt">&t</span>< classGAPinput else<span>
<span class="GAPprompt">></span> <span class="GAPinput"> return globali + 2;</span>
<span class can; after making it writable tocontinue
<class"">></> <span="GAPinput">nd;<span
<span class=GAPprompt">&;/><spanclass"GAPinputIsReadOnlyGlobal"xx");<span
function ( )
return3 +;
end
<prediv>
<div="func>tableclass"func="100%"<tr>td class"tdleft"><codeclass"‣ IsReadOnlyGlobal</>(<var class"Arg><var/d>td=tdright">nbsp;unction )</td></tr></table></div>
<p>returns <code class="keyw">true</code> if the global variable named by the string <var class="Arg">name</var> is read-only and <code class="keyw">false</code> otherwise (the default).</p>
<div class="func"><table
<p>marks the globalvariable named by the string <varclass"Arg>name</var> read-only.</>
<p><h5>4.- ValueGlobal</>
<p><a div class"< class=unc" ="100"<>td">code ="">&8227;ValueGlobal/ode>(< class"">name</> )
<h5>4.9-3 MakeReadWriteGlobal</h5>
<div
<p> the variable by string classArg</> as-write/p
<p>A warning is givenh549-IsBoundGlobal</h5
<div class="example"><pre>
<span class="GAPprompt">gap></preturns class"true<code if a currentlybound tothe variablenamed by string<var class=Arg">name> and< class"">false>otherwise.p 17
<spanp< ="X829A5F0E811F77D3" name"X829A5F0E811F77D3">/>/>
false
<span class="GAPprompt">gap></span> <span class"<tableclass"func width%>tr class=tdleftcode class"">227;UnbindGlobal<code(var="Arg></var>)</td>tdclass"">(&;function&;)<td</></table<div 15
<span is < class"</var not bound The global variable named by <var class="Arg"></var>must be writable an error is raised.</p>
<">xx: 16</panjava.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
Variable: 'xx' is read only
not inany function
Entering break read-eval-print loop ...
you'uit'toquit to outer loop,or
you 'return;'afterit to
<span class="GAPbrkprompt">brk></span> <span class="GAPinput">quit;</span>
<
true
< classGAPprompt>>/span <spanclassGAPinputMakeReadWriteGlobal(xx</>
<span class="GAPprompt">gap></span> <span class="GAPinput">xx 16
<span classjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
false
<<pan="">gapspan":16/>
< =X847706237E72418F"/pjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
<h5>4.9-4 MakeConstantGlobal</h5>
< class==""tr="tdleftcode ="func;MakeConstantGlobalcode(< "Arg">name/var>)/><td="tdright"(nbspnbsp/>/>/ablediv>
<p>MakeConstantGlobal ( <var class="Arg">name</var> ) marks the global variable named by the string <var class="Arg">name</var
<p>A warning is given if <var class="Arg">name</var> is already constant.</p>
<div class="func"><table /re>
<p>returns <code class="keyw">true</code> if a value currently ="X876A6EB68745A510"=X876A6EB68745A510>/
<p><a id="X829A5F0E811F77D3" name
<h5>4.9-7 UnbindGlobal</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="<p>This function returns an immutable (see a href="hap12_mj#7F0C119682196D65>span="RefLink">12.<spana)sorted (see ="chap21_mj.#X80ABC25582343910"< classRefLink.</></> listof the variable known thesystem includesnames variables were but now unbound some names have been but have known the by routesp>
<>.-10NamesSystemGVars</>
<p>A warning is given if <var class=div classfunc< class"" width%>tr classtdleft>code=func#8227 NamesSystemGVars/ode)/>td=tdright&bsp&;<td/r<table/div
<div class="func"><table class="func" width="100java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
p function ( a href.#X7F0C119682196D65 class>./></a)sortedsee =".html#X80ABC25582343910<class"">2119/pan< of theglobal variable known the . This includesnames of variables which were bound have now beenunbound and someother names which havenever been bound but have known the by various routes./>
<div=""><tableclass=func=100%"<>tdclass=tdleft>codeclass""&8227; NamesSystemGVars</code>( )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function returns an immutable sorted list of all the global variable names created by the <strong class="pkg">GAP</<pan class"APprompt">gapgt/pan < =GAPinput : functionn <span
<div class="func"><table class class="APprompt>gt<span <span class""> :=f1+f2;span
<pThis returns immutablesorted ofthe variable created the was, to a value iscurrently bound</p>
<p<aidX7DF8774F7D542298name"</>/>
<h4>4.0 <spanclass"Namespaces for< class="pkg">GAP</strong> packages<span<h4java.lang.StringIndexOutOfBoundsException: Index 99 out of bounds for length 99
< mentioned <ahrefchap4_mj#X816FBEEA85782EC2"span=RefLink">49</pan/a>aboveglobalshare namespace Thiscanrelatively lead name, in when <strong"">GAP>packagesloaded .To code wayhavepackage namespacebreaking of strong"">GAP> languagethe following rulehas been devised:</p>
<p>If in package code a global variable that ends with an <q>at</q>-character <code class="code">@</code> is accessed in any[1,1 ,3,,813213455]
p thatifafunctionvar=></var is defined above then classcodeNumberArgumentsFunctionclass>var<code returns the of argumentsincluding final)(ee< ="func"NumberArgumentsFunction/>(a ="chap5_mj.htmlX877F03F77FD74C98">span class"5.1-/>/>)</p>
<p>Using the <code class="code">...</code> notation on a function <var class="Arg">f</var> with only a single named argument tells <strong class="pkg">GAP</strong> that when it encounters <var class="Arg">f</var> that it should <span class="GAPprompt">gt;/span> <<span classGAPinput> stack [;</span>
<p>Also see Chapter <a href="chap5_mj.html#X86FA580F8055B274"><span class="RefLink">5</span></a>.</p>
<> following a coupleofexamples oftypical use such function</
<div class="example"><pre>
<pan=GAPprompt>/pan> span="">Sum( [1.100,{}-gt;x^ ;/span> 338350
<span class="GAPprompt">gap></span="GAPprompt>apgt<span <spanclass"">.(4) .(5 ;B.push(6 ;/span>
<
<span
[ 5, 3, 3, 2, 1 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">f := {x,y...} -> y;
<span class="GAPprompt">gap></span> <java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
[ 23, ]
<span class="GAPprompt">gap><java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
function( ) ... end
<span
function ( )
return 2;
end
<span class="GAPprompt">gap></span> <span class="GAPinput">f();</span> 2
</pre></div>
<p>The <code class="code">{</code> and <code class="code">}</code> may be omitted</var>[, <var class"Arg">arg</var,...] <code/>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Sum( List( [1..100], {x} -> x^2 ) );</span> 338350
<span class="GAPprompt">gap></span> <span class="GAPinput">Sum( List( [1..100], x ->p> <strong="pkg"GAP<strong the classArgfunction</>. Usually< classArg">unction-var</var> isavariable,and<trongclass=pkg">GAP> does more taking value this.It is allowed though <var="">function-var<var a more complexexpression,suchas areference an oflist see < ="hap21_mj.html#7B256AE5780F140A><span class=RefLink">21</>/> class">varclass"Arglist-var/=Argint</>]/>,or to component ofa (see Chapter<a href"chap29_mj.htmlX7AA1073C7E943DD7"><pan ="RefLink">29/><a)<ode="code> class=Arg"recordvar =Arg">ident/var></code>.In any case <strong class="kg</> tests the is function Ifit not classpkgGAP<strong an.</p>
< <strong"pkg>GAP</strong> checks that number actual arguments <var class=">-expr>s agreeswiththenumber em arguments/m> as in function. If do agree classpkg</strong> anerror. exception the when function a variable argument, which denoted adding ="code">.<> after final. this there be leastas arguments there formal arguments>before thefinal</> and beany number ( <ahref.#X815F71EA7BC0EB6F<span class=RefLink>11<span/>for)./>
</pre></div>
<pWhen definition a functionvar classArg</var evaluated another <var="">fun2var> < classpkgGAP/> binds the inside function var="">fun1<> that identifiersof an argument orlocal <var="">fun2</var to corresponding variable.This ofbindingsis theenvironment of functionvar="">fun1>. <var="">fun1variscalled body is executed this environment Thefollowing implementationofa stack thisValues be ontothe andthenlater popped againTheinteresting thinghere that functionscode class="push/>and <codeclass"">op/> inthe record returned by< class"ode</code access local <codeclass"">tack<code <code="code">Stack</code.Whencode="">tackcode>is called, theidentifier codeclass"stack/code>iscreated.Whenthe function definitionsofcodeclass"code">push</code> and <code class="code">pop</code> are then evaluated (as part of the <code class="keyw">return</code> statement) each reference to <code class="code">push</ode> code class">op/code>are evaluated( part thecode class=keywreturncode> statement)each to <code class="code></code> is bound to this new variable Note alsothatthetwo stacks<codeclass=""A</>and< =code>B<code do interfere becauseeachcall of <odeclass""></>createsanewvariable codeclass"">stack</code./pjava.lang.StringIndexOutOfBoundsException: Index 1529 out of bounds for length 1529
<div class="example"><pre>pNowthebodyofthefunction is statement isexecuted. If identifier one the arguments formal appears the bodyof function refers the variable was for formal or formal, evaluatestothevalueof thisvariable.<p
<span class="GAPprompt">gap></span> <span class="pIfduring theexecution of the of the function codeclass="keyw<>statement expression <href".html#X812C6ABC7A182E9E"< =RefLink>.5a , thethe expressioncode""></code.If during executionofthe a<ode class"returncode without an expressionis executed,execution of the body is terminated the function call does not a value, in which case we call this call procedure call (see < href="chap4_mjX825803DE78251DA6>span =RefLink"4.15-2<span></>) Ifthe execution of the completeswithoutexecutionof a < class"keyw></>statementthecallproducesno,andweabout callp
<span class="GAPprompt">></span> <span class="GAPinput"> local stack;</span
<span class="GAPprompt">>="GAPprompt>>span span class=GAPinput"Fibonacci ;span
<spanpre/>
<span class="GAPprompt">></span> <span class="GAPinputpTheaboveexample shows to thefunction <codeclass="func<code (ahref.htmlX85AE1D70803A886C>spanRefLink.3<spana)withargument class"11/ode>, the following one shows call to the operation <codeclass"">RightCosets/ode> (<a href="chap39_mj#X835F48248571364F"< class=RefLink>39.-<span<a>)wherethesecond actualargument isanother call.<p>
<span class="GAPprompt">></span> <span class
<span class="GAPprompt">></span> <span class="GAPinput"> enddiv classexample<re>
< classGAPprompt&;</span>< classGAPinput popfunction(<span
<span class="GAPprompt">></span> <span class="GAPinput"> return Remove( stack) ;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> end</span>
<span id="X867D54987EF86D1D" name=X867D54987EF86D1D"<a<p>
<span class="GAPprompt">></span> <span class="GAPinput"> end;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">A := Stack();;</span>
< classGAPpromptgap&;</span>< classGAPinputB := Stack();;/span
<span class="GAPprompt">gap></span> <span
<span="GAPprompt>><span><spanclass"GAPinputBpush ) Bpush 5 ); B) B.push 6)</span>
<span class="GAPprompt">java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 3 2 1
<span class="GAPprompt">gap></span> <span classThefollowing shows tocodeclassfuncSize/> (<ahref.#X858ADA3B7A684421span="RefLink">304-<spana>) passing options class"hard/ode> (iththe <code class""true/ode>and<code class="code>tcselection>( the< class">"xternalcodeas).<p> 6 5 4
<>/>
<pThisfeature should be rarely,since implementation in <strong="pkg">AP</strongis notvery efficient.<p>
<p>The function call has the effect of calling the function
<p>First>4.13<spanclass=Heading></span/>
<p>Next <strong class="pkg">GAP
<p>Now <strong class="pkg">GAP</strong
<p>Next the arguments <var
<p>The new variables corresponding to the formal locals are initially not bound to any value. So trying to evaluate those variables before something has been assigned to them will signal an p>The operator code="code=/ equality operands andevaluatesto < class="<codeif equal codeclass">false/> otherwise. Likewise <code class="code&;gt/code> oftwo.For ofthe ofequalityis in respective. indifferentfamilies hrefchap13_mjhtml"><panclass"RefLink>13<spana) areequal..,code=code>/>evaluates caseclass"></code>, and<odeclass"code&;><> evaluates <code class"">true>/>
<p>Now the body of the function, which is a statement, is executed. If the
<p>If during the executionjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<div class
<span class=GAPprompt>ap&t<spanspan="">Fibonacci(11 ;<span> 89
</pre<>
<p>The above examplep>Notethat class"">;</>implements<em ordering/m ofobjects ( can used example sort of elements). Therefore in general <code class="code"><</code> will not be compatible with any inclusion relation (which can be tested <codeclass"func">IsSubsetcode (a hrefchap30_mj.#X79CA175481F8105F<span classRefLink>0.-</></a>)( exampleit possible compare groups <code&<code ordering all permutationgroups, but ordering not with relation beingsubgroup.<p>
<div class="example"><prepFor objectsstrong=pkg</strong <em</emprovide ordering <codeclass"&;</>. reason this isthat a total ordering of all <strongclass"">GAP<strong> objects would be hardtomaintain when new kinds of objects are introduced, such a ordering ishardly used in its full generality.</>
< class&;<spanspan ="GAPinput">RightCosets( G, Intersection( U,V ));/>
<p><a id="Comparison operators, including the operator<code class="></code < ="chap21_mj.htmlX808A207182B2F84F"> classRefLink>.<span>/>) are associative, Hence notto <codeclass=class"">a/varvar classArg>b<var <gt; <var class="rg></ar> = <var class=Arg><var</ode> you must <odeclass=code"< ="">a/> = <varclassArg<var)&;>( classArg<varvar="">d</var>/> instead. comparisonoperatorshave precedencethan logical operators ( <ahref=chap20_mj#X79AD41A185FD7213<spanclass=RefLink">204</pan>/a) precedence thanthearithmeticoperators (ee<a hrefhref="chap4_mj#X7B66C8707B5DE10A>spanclassRefLink>.<spana>.Thusinstance =code< class">a/var> * var class"">b<var =<var class=""c/> and <varclass""d/>/ode>is interpretedas< class="ode"(varclassArg"><varvar="rg"b/ar= varclassArgc/var) and class">d<var><code></p>
<h5>4.12-2 <span class="Heading">Function Call With Options</span></h5>
<div =""var="Arg"left</var+var="Arg>-expr/>/ode><pjava.lang.StringIndexOutOfBoundsException: Index 101 out of bounds for length 101
<span class="GAPprompt">gap></span> <span
pan
<span
</pre ="> class=""leftexprvar varclassArg>-<>/><>
<h4>4.13 <span class="Heading">Comparisons</span<><code class="code"><var class"Arg"left> classArg"rightexpr/var></code>/pjava.lang.StringIndexOutOfBoundsException: Index 101 out of bounds for length 101
<p>The operator <code class="code">=</code> tests for equality of its two operands and evaluates to <code class="keyw">true</code> if they are equal and to <code class="keyw">false</code> otherwise. Likewise <code class
<p><code class="code"><var<>code="code"< class"a/>mod <var=Arg">b/></code integer leftvar=""a<> and non integer operand class"<var>, defined asfollows. If < class=Arg><var and <var ="Arg<>are integers<codeclass"< class=Arg>a/var> mod < class=Arg"b/ar><code is var=Arg/> code=code0.| ="">b/>| </> satisfyingcode=""< class>/> =var=Arg<varvar="">b</ar<varclass>/var<> for< =Argwherehave integers)pjava.lang.StringIndexOutOfBoundsException: Index 787 out of bounds for length 787
<p><codejava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
<p><code class="code"><var class="Arg">left-expr<
p operatorscode=code>/code, code class="code>-code, <ode class"">*</ode>, <codeclass="code"//>,<codeclass="">mod/> <code ="code^/> meanings generally operands variousthebasically meaningsfollowsjava.lang.StringIndexOutOfBoundsException: Index 429 out of bounds for length 429
>=code =">/> + varclass=">b><codedenotes ofelementsclass"/> and < class=Arg><var<p
<p><code class="code"><var>
<p
<p><code class="code"><var class="Arg">a</var> / <var class="Arg">b</var></code> denotes the multiplication of <var class="Arg">a</var
<p><code class="code"><var class="Arg">a</var> mod <var class="Arg">b</var></code>, for
<>If var="Arg></> a rationalnumber varclass=Arg></ar isanon- ,and code class=code"< =Arg">a</var var class"">/>/< class="n<var> varArg><varvar"">n<var coprime with var=Arg/> positive < class"">var=Arg/> mod class><var<code the < classArg/> the range class"code"0.< class"><var>| - 1<code that <var class"">m<> is congruent <code ="codevarArgr/< =Argn/></codemoduloclass">b/ar,and<varclass"">r/var> is called the <q>modular remainder</q> of <var class="Arg">a</var> modulo <var class="Arg">b</var>. Also, <code class="code">1 / <ar class"Arg">n/> mod <var class="rg<varcode is called <qmodular<q <var=Arg/>modulo var ="Arg"><var.(Apairofintegersissaidto <em</> (orem primeem>)iftheircommondivisor 1)</p>
<p>With the above definition, <code class="code">4 / 6 modjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<p><em=example>
p ="code < class=code" alsounary < class"+code is ignored. The codeclass=code></ode> the inverse its operand; over theintegersitis equivalent <code="">/
<p><code class="code">^</code> denotes powering of a multiplicative;&; 0then 16i ;<span
<> <emprecedence<> those as. powering <codeclass"ode"^/> has highest, followedbythe operators class><codeandcode class="-/ode>, which arefollowed bythe multiplicativeoperators <ode class""></>, code ="code/> < class">mod</code>andthe additivebinary operators codeclass="">/> and class=""<code have lowest . That means theexpression codeclass="code"- -2 3 + 1/code> is interpreted as <codeclass"ode( -) 3 +1/> in use to yourintention<>
<gap;
<p>The arithmetic operators have higher precedence thanpAs can from example warning in addressusers are tolanguages <codeclasscode>/> instead code="":/>denotesp
<div class="examplejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<class;span=">*2+9; simple expression/> 13
</pre></div>
> operationsfor operations the introduced, < =".html#X7A2914307963E370"< class31<spanp
<p><a id<>.- <pan><span>
<h4>4.15 <span class="Heading">Statements</span/>
p =pkg<> programs of of-called>statements> Thefollowing of:
<ul>
<li><p>Assignments (see Section <a href="chap4_mj.html#X7E6A50307F4D3FAE"><span class="RefLink">4.15-1</span></a>),</p>
<>
<li> classkeyw</code (see <href=chap4_mjhtmlX87AA46408783383F"spanclass""415-4<span<a>,/p>
/>
<li><p><code( numbers=[1,4, , := "string" )
</li>
<li><p><code class="keyw">p>If the class>/ isfunction then function returnvalueIfthe function not an signalled you loop ahrefchap6_mjX8593B49F8705B486 class>4></) usual leave codecodequit. enterclass""returnArg<>;/code expressionvar="">-expr> assignedto variable executioncontinuesassignment
pStatements,unlike , have value are only produce effect example assignment the of avalue a, class<code has effect executing sequence all list on will <</>of butem</em statements emphasize difference.
<p>Empty statements are permittedAem/ does avalue does produceaside name is what ,.,< class"
<p>A sequence of one or more statements is a es not value produces . Proceduresare only effect a conventionthename aprocedureis , denotingthe doesg,< class""><">"<> codecode>Sort><p
<p><code class="code"><var class<>divjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
<p>The <em>assignment</em> has the effect of assigning the value of the expressions <var class="Arg">expr</var> to the variable <var class="Arg">var</var>.</p>
<p>h5.- < class"If/span>h5
<p>Note that variables do not have a type>codeclasscodeif classboolvarthenvar classstatements1/> elif class>oolexpr2>thenvar="">statements2/ar} <varclass""statements3 fi<p
<> thevar="></var> is afunction call then this functionmustreturn a value. If thefunction does not return avalue an error issignalled and youenter abreak loop(seeahref="chap6_mj#X8593B49F8705B486"< ="">6.</></>.As usualyoucan leave the breakloop with codeclass="">quit;<code. you enter < class="code class">-expr/>;</> the valueof the expression varclass="">return-expr</> assignedto the , andexecution continues the assignment.<p>
<div class="example"><pre>
<span class="GAPprompt spanGAPprompt&/panspan=""f2 x ) f1 ;;<>
<
value: 4
Function Calls: < expr1 ifthen fielse;
return
called from
<function>( <arguments> ) called from
Entering .
you
you can supply span""brk;/> span="GAPinput" hello;/> ""
</pre></div>
<p>nthe example function classcode></code <codeclass""f1> with argument class><code and ="f1</>doesnotreturn a value ( only prints a <q>codeclass="code>:.<code/)theclass"return/""<codecannot be executed. errormessage says that it possible to return appropriatevalue, and the returned string< class="">"<codeis byclass"f2< instead returnvalueofcodeclass"f1>/>
pclassvar">-var/var>( [var class"">arg-expr</> [,var class"">arg-expr</var>,..] )</code><pjava.lang.StringIndexOutOfBoundsException: Index 147 out of bounds for length 147
<p>The classGAPprompt;<span =""> i &t then>
<pA <></em return but nota effect aconventionthe of is,denoting the , e.,< classcode"ength<code>,code ="code"Concatenation"/>andcode="code"""</>.p>
<p>A <em>procedure</em> is a function that does not return a value but produces some effect. Procedures are called only for
< are exceptions<strong""GAP> thatbothavalue produce effect example code="">Sortex(a ="chap21_mjX87287FCA81E2B06Aspanclass"".-/pan></> sorts and returns thecorresponding permutation ./p
<p><a id="X875000188622700D" name="<The< =""</>loop executes the statement <varclass="Arg< condition=Arg/<class"true<code><pjava.lang.StringIndexOutOfBoundsException: Index 211 out of bounds for length 211
<h5>4.15-3 <span class="Heading">If</span></h5>
> between="/and codeclasskeyw><code codeclass"">ntil</code> loop ( <a ="chap4_mj#>="15span>isthatthe< =Arg">statements> in < ="">repeatcode<code><code executed once theclass><var < class"<code> are not executed atall if< class=Arg"bool<var < =""></codeat first./>
<p><code class="code">if <var class="Arg">bool-expr1</var> then <var class="Arg">statements1</var> { elif <var class
<p>The <code class="keyw">if</code> statement allows one to execute statements depending on the value of some boolean expression. The execution is done as follows.</p>
<p>First the expression <var class="Arg">bool-expr1<<p>The example a <code class"keyw"></>loopclass( ,\/> exceeds""\200)/panp>
<p>Otherwise the expressions <var class="Arg">bool-expr2</var s &t; 200do<span>
p <class"< belongs thesecond codeclass=keyw"ifcode, whereasin/>
<div class="example"><pre>
if =""repeat>var""boolexpr>;/><p>
</pre></div>
<code="keyw></>partbelongs the first <ode class=keyw"<code ./p
<p>SincepFirst class"">statements<> are. Then classArgboolexpr/> is.If evaluatesto<ode class"">truecode the class></code>loop thestatement immediately following thecode classkeyw</code loop is executed. Otherwise itcode=>false>the begins with execution="Arg">tatementsvar>
<div class="example"><pre>
abs :
</pre></div>
<p>which would, even if legal syntax, be meaningless, since the <code class="keyw">if</code> statement does not produce a value that could be assigned to <code class="code">abs<p>If < class"bool/var evaluate code class""</code or < class="keyw/ error isand seechap6_mj#"> class=""64/>/> entered As thebreakloopwith< =code"quit If enterreturn> with nextimmediately <code="></code. you < class=return false;/> continues < class=Arg>statements/var> whichthenext evaluationof ""-</> cause another error.<p
<p>If one of the expressions <var<The ="keyw"<code exampletheascode=keyw<>loop , to squares""\122,ldotsuntilsum class">200\>>
<div class="example"><pre>
<span="GAPprompt">gap;</> <span="GAPinput> : 10;/spanjava.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
<span ="">gt span="APinput =i 1 =s+i^;span>
<span""&;span=GAPinput : 1/>
<span class="GAPprompt">></span> <span class="GAPinput"> elif i < 0 then</spanspan classGAPpromptgap;</span> < class"">s;/>
<span/re></div>
<span class="GAPprompt">></span> <span class="GAPinput"> else</span< class<,seehref=chap4_mjX7B60C6127E183021 class>.7>>/
<span class="GAPprompt">><p>aid"78783E777867638A name="X78783E777867638A">/a>/>
<span class="GAPprompt">></span> <span class="GAPinput"> fi
<span class="GAPprompt">gap></span> <span class="GAPinput">s; # the sign of i</span> 1
</pre></div>
<p><code class="code">while <var class="Arg">bool-expr</var> do <var class="Arg">statements</var> od;</code></p>
<p>The <code class="keyw">while</code
<p>First <var class
<p>he between <codeclass="">while/> loop andthe < class""repeat><codeclass"</ode>loop(ee< href="hap4_mj.html#X8295CBF47FAA05C9">< class=RefLink>4.-5<< is thevarclass=rg"statementsvarin code=keyw<codecode="></code areexecuted at leastonce, the < class"Arg<varcodeclass><code < class>-<var=keyw/> first>
<p>If <var
<p>The following example shows a <code class :=list
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">i := 0;; s := 0;;</span>
<span class="GAPprompt">gap variable := loop_listloop_index
<span class="GAPprompt">> :=loop_index 1
<span class="GAPprompt">></spanprediv>
<span class="GAPprompt">gap></span <loop_index</q> different for < class<>looptheseof =""for> do interferewith each./> 204
</pre></div>
<p>A <code class="keyw">while</code> loop may be left<ode=codefor=></> [ class</>..< class></varvar="></var> ;</code>pjava.lang.StringIndexOutOfBoundsException: Index 169 out of bounds for length 169
p =X8295CBF47FAA05C9="X8295CBF47FAA05C9>/>/java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
pIf class"bool-expr<var>doesnot < =keyw"></codeor <code class"">false</code> an error is signalledand a break loop (see <a href="chap6_mj.html#X8593B49F8705B486"><span class="RefLink">6.4</span></a>) is entered. As usual you can leave the break loop with <code class"code">uit> < ="> ;/codeexecutioncontinuescodeclass=eyw"/codeIf";codeexecutionatvar=Arg><var>after thenextevaluation var class"">boolexpr/var> may cause another error./pjava.lang.StringIndexOutOfBoundsException: Index 708 out of bounds for length 708
<p class&;<span<pan class"l : 1,2 3,4 ]/span
<div class="example"><pre> span">><span <spanclass="GAPinput">i : 0;;s: 0;span>
<span class="GAPprompt">gap></span> <span class="GAPinput">repeatspan="GAPprompt>gt<span><spanclass"APinput" imod2=0then Add l, ;fi;/pan>
<span class="GAPprompt">></span> <span class="GAPinput"> i := i + 1; s := s + i^2;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> until s > 200;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">s;</span1,,3 , 5,6,3699] 204
<p>A <code class="keyw">repeat</code> loop may be leftdiv="example>pre>
<p>The execution of the <code class="keyw">for</code> loop over a list is exactly equivalent to the following <code class="keyw">while</code> loop.</p>
<p>with the exception that <q>loop_list</q> and statements
<The class"-/>isveryoften arange see =chap21_mjhtml#X79596BDE7CAF8491"< ="RefLink">.22/></>./>
<p><code class="code">for <var class="Arg">variable</var> in [<var
<p>corresponds to the
<p><code class="code">for
<p>in other programming languages.</p>
<div class="example"><pre>
<span class"APprompt"gap<spanspanclassGAPinput> :0;/pan
<span class="GAPprompt">gap><span="GAPprompt"gap<spanspan=GAPinputfor xin</span
<span="GAPprompt">&;</span>< classGAPinput s: s +i</panjava.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
<span class="GAPprompt">></span> <span class="GAPinput">od;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">s;</span> 5050
</pre></div>
<p>Note in the following example how the modification of the <em>list</em> in the loop body causes the loop body also to be executed <spanclass"GAPprompt"gapgt</span<span class=GAPinput>count;</span>
<p>Note in the following example that thep> mayuse muchlessstorage, the may more thanlist all elements>
<div class="example"><pre>
<spanclass"GAPprompt">><spanspan class=GAPinput> : [12 , 4,5,6];/>
<span class="GAPprompt">gap></span> <span class="GAPinput">for i in l do</span>
<span class="GAPprompt">>
<span classp><codeclass"</code> may be left prematurely using<code ="keyw<> see href.html#X7B60C6127E183021<panclass="RefLink">4.-7</pan> This well an, waydomain ./>
<span class="GAPprompt">></span> <span class="GAPinput">od; Print( "\n<p><a id="7B60C6127E183021=X7B60C6127E183021/>p 123456
<span class="GAPprompt">gap></span> <span class="GAPinput">l;</span>
[ ]
</pre></div>
<p><code class="code">for <var class="Arg">variable</var<>codeclasscode">reak;code><pjava.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
<p>It is also possible to have a <code class="keyw">for</code>-loop run
<div class="example"><pre>
while not(iterator) do
variable := NextIterator,)5) )
statements
java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 3
</pre></div>
<p>codecode"for< class"rg>in ="</var do <var class="Arg"</>;/>/>
<p><code class="code">for <var class="Arg">variable</var> in AsList(<var class classGAPpromptgtspanspan="GAPinput">ifOrderx) 3then/>
<p>but may use much less storagespan="GAPprompt"&;/> <span=GAPinput">fi; Print(x"\n"; od;</span>
<p>See <a href="chap30_mj.html#X85A3F00985453F95"><span class="RefLink">30.8</span></a> for details about iterators.</p>
<p>A <code class="keyw">forpre<div>
< =X7B60C6127E183021=X7B60C6127E183021>/>/>
<h5div="example"<pre>
<p><code class="code">break;</code></p>
<p>The statement <code class="code">break;</code> causes an immediate exit from the innermost looppre><divjava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">g := Group((1,2,3,<h5>4.15-9 <span class"Heading"Return( without<span/5>
Group([ (1,2,3,4,5), (1,2)(3,4)(5,6) ])
<span class="GAPprompt">gap></span> <span class="GAPinput">for x in g dop> this form< class"eyw"returncode terminates callthe innermost function thatcurrently,andreturnsto functionAn issignalled no is executingNois the./>
<span class="GAPprompt">></span> <span class="GAPinput">if Order(x) = 3 then</span>
<span class="GAPprompt">></span> <span class="GAPinput">break;</span>
< classGAPprompt&;<span><pan classGAPinputfi;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">x;</span>
(,5,)346
</pre></div>
<> is error use statement than a loop/>
<div=""><re
<span class
Syntax error: 'break'p>a idX8732D9257FFCEA1B" name="X8732D9257FFCEA1B"></a>/>
</pre></div>
<h5>4.15-9 <span class="Heading">Return (With or without Value)</span></h5>
<p><code class="code">return;</code></p>
<p>In this form <code class="keyw">return</code> terminates the call of the innermost function that is currently executing, and control returns to the calling function. An error is signalled if no function is currently executing. No value is returned by the function.</p>
<p>In this form <code class="keyw">return</code> terminates the call of the innermost function that is currently executing, and returns the value of the expression <var class="Arg">expr</var>. Control returns to the calling function. An error is signalled if no function is currently executing.</p>
<p>Both statements can also be used in break loops (see <a href="chap6_mj.html#X8593B49F8705B486"><span class="RefLink">6.4</span></a>). <code class="code">return;</code> has the effect that the computation continues where it was interrupted by an error or the user hitting <strong class="button">Ctrl-C</strong>. <code class="code">return <var class="Arg">expr</var>;</code> can be used to continue execution after an error. What happens with the value <var class="Arg">expr</var> depends on the particular error.</p>
<p>For examples of <code class="keyw">return</code> statements, see the functions <code class="code">fib</code> and <code class="code">Stack</code> in Section <a href="chap4_mj.html#X815F71EA7BC0EB6F"><span class="RefLink">4.11</span></a>.</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">an style='color: green'>8227; SyntaxTree</code>( <var class="Arg">f</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Takes a GAP function <var class="Arg">f</var> and returns its syntax tree.</p>
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 und die Messung sind noch experimentell.