Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/VDM/VDMSL/pacemakerSL/   (Wiener Entwicklungsmethode ©)  Datei vom 13.4.2020 mit Größe 3 kB image not shown  

Quelle  chap4_mj.html

  Sprache: HTML
 

 products/Sources/formale Sprachen/GAP/doc/ref/chap4_mj.html


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         http:/wwworg/html1strict

<html xmlns="http://www.w3.org/
<head>
<script type="text/javascript"
  src://cdn.netnpm@2.?configTeX-AMS-MML_HTMLorMML"
</script>
<title>GAP (ref) - 
<eta-equiv=content" content="text;charset=UTF-"/
<meta>
<link type"/javascript"
<manualtype=text"<script
<script type="text/javascript">overwriteStyle();</script>
</ead
<body ="chap4"  ="jscontent()>


<div  rel=stylesheet="textcss ="manual.css

<script src=manual" type"text/javascript"<script

<p id="mathjaxlink" class>
<p><a id="X7FE7C0C17E1ED118" name="X7FE7C0C17E1ED118"></a></p>
<div class="ChapSects"><a href="chap4_mj.html#X7FE7C0C17E1ED118">4 <span class="Heading">The Programming Language</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap4_mj.html#X7B5FF6827DFBDF20">4.1 <span class="Heading">Language Overview</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </body ="chap4  onload"jscontent()
</pan>
</div>
<div class="ContSect"><span java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap4_mj.html#X7C53CEFC8641B919">4.4 <span class="Heading">Whitespaces</span></a>
<span>
</div ="ChapSects>ahref".#X7FE7C0C17E1ED1184 < class"TheProgramming <span</
<div"html"41 span"Language Overview/></>
</span>
</div>
<div class="ContSect"/>
<span
<div class="ContSSBlock/>
< classContSS />spanclass"">  <span ="chap4_mjhtmlX85CF993B7D19F2C4">46-1 IsValidIdentifiera></>
<<>
</>
</div>div
<div class="ContSect">div="ContSect>spanclass"oclineclassnocss>nbspspanhref.htmlX7C53CEFC8641B919>.4 < class">Whitespaces/></a>
</span>
</div>
<div class="ContSect"><span class="tocline<span>
</pan
<div class="ContSSBlock">
<span class""><span class=tocline"spanclass""&;</>ahref=chap4_mj.html#X860313A179A5163F">4span="">Identifiers<span/
<span class="spanclass"ontSS<br/<span ="nocss">nbsp;/>a =chap4_mj#X85CF993B7D19F2C4"46- IsValidIdentifier</a<span
</><div
<div class"< =tocline">< classnocssnbspspan>a href=chap4_mj#X816FBEEA85782EC2">.9 <pan class"">  GlobalVariablesspan<a
</span>
<divclass"java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
<span="ContSS"><br>span ="nocss"&;nbsp> =chap4_mj#7CD3523B84744EB249-1 IsReadOnlyGlobal/>span
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap4_mj.html#X850CE44478254F27">4.9-2 MakeReadOnlyGlobal</a></span>
<span class="ContSS"><br /><span class="nocss">  </span><a 
<span class="ContSS"><br /><span class="nocss">  </span<div>
<span classdiv class=ContSect<span class"tocline"><spanclassnocss>nbspspan><a href=chap4_mjX7A4C2D0E7E286B4F"48  spanclass"Heading">Variables/>/ajava.lang.StringIndexOutOfBoundsException: Index 165 out of bounds for length 165
< classContSS /< class"ocss>nbsp&;</span<a ="chap4_mj#X823D4BC378395B32">49-IsBoundGlobal</a>/span>
<span class="ContSS"><br /><span class="<panclass="ContSSbr/< =nocss;nbsp>a hrefchap4_mj.htmlX7BABB3E77F52626C"48-2 </a</pan
<"ContSS"><br /<span="nocss"nbsp;span =chap4_mj#X7D39D3E17CF49F5B>.- BindGlobal>/pan
<spandiv ="ContSect>spanclass""< =nocss>nbsp<span< =chap4_mjhtmlX816FBEEA85782EC2">49< class"More AboutGlobalVariables/pan<a>
<span class="ContSS"><br /><span class>
< classContSSbr >span="">&; /><a ="chap4_mj.tmlX870169447AF490D8">4.11 NamesUserGVarsa<span
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap4_mj.html#X7DF8774F7D542298">4.10 <span class="Heading">Namespaces for ="ContSS>br />span =nocss>  /span><a href="hap4_mj.htmlX850CE44478254F27">4.9-2 MakeReadOnlyGlobal</a></span>
</span
</div>
<div class="ContSect"><span class="tocline"><span class="nocss<span class="ContSS><br /<spanclass"ocss">nbsp&bsp;</span><a href="chap4_mj.html#X847706237E72418F"4.-4 MakeConstantGlobal/a></span
<span
</div>
<div class="ContSect"><span class="tocline"><span classspanclass"<br >spanclass"ocssnbsp;/pan href.html#823D4BC378395B32.- IsBoundGlobal/>/>
</>
<div class="ContSSBlock">
<span="ontSS><br/<span class=nocss">&bsp;</span href"chap4_mj.html#X80B93A9C7E0A57F4">4121 span="Heading">Function With</span>/>
</span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap4_mj.html#X867D54987EF86D1D">4.12-2 <<pan class"< >spanclass=nocss>nbsp&;<>ahref"chap4_mjX876A6EB68745A510>.- NamesGVars<a<span
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap4_mj.html#X7A274A1F8553B7E6">4.13 <span class="Heading">Comparisons</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </spandiv>/div
</span
</div>
<div class="ContSect"><span class/pan
<span
<div class
< ="toclinespan=";>< =".#78C70489791FDF43. spanclass""Function Calls<span<a>
</span="
< class >span="nocss">; ><ahref=chap4_mjX80B93A9C7E0A57F4.- span class"">Function WithArguments<span>/>
</span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap4_mj.html#X875000188622700D">4.15-3 </>
</span>
<span class="ContSS"><br /><span class/>
<java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap4_mj.html#X8295CBF47FAA05C9">4.15-5 <span class="Heading">Repeat</span></a>
</span>
<span class="ContSS"><br /><span class="nocss">  </span><a href="chap4_mj.html#X78783E777867638A"><>
</span>
<span="ContSS"><br>span="nocss>nbsp&;/>a href="hap4_mjX7B60C6127E183021"4157< class=Heading">Break></>
</pan
<spanspan ="ContSS">< >span="nocss">nbsp&;</><a href=chap4_mjhtml">415-< class=""> Calls/>/>
</span
<span class="ContSS"/span>
<span
</div></div/>
< classContSect"><span class="tocline<spanclassnocss&bspspanahrefchap4_mj.html#X8732D9257FFCEA1B">416 span class"Heading">Syntax></a>
</span>
<div class="ContSSBlock">
<span class"ContSS"><br /><spanclass="nocss"  <spana href href"chap4_mj.html#X81558D66810BEA67>4.161 SyntaxTree</a></span>
</div></div>
<div

<h34 <span classHeading> ProgrammingLanguage<span/h3>

<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

<p>a ="X7B5FF6827DFBDF20name"X7B5FF6827DFBDF20<a<p

<h4>4.1 <s=ContSS />span class>nbsp;nbspspan< href=".html#X812C6ABC7A182E9E">4.- < class"Return Withor withoutValue)/>/>

<p>First we>

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   
    \
  2   3
<

<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><a id="X80A85A707B6F4BE7" name="X80A85A707B6F4BE7"></a></p>

<h4>4.2 <span class="Heading">Lexical Structure</span></h4>

<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>


<div class="example"><pre
"    '           *    +    ,   -#
./:;;    =   &;    ~
[    \    ]    ^    _    {    }    !
</pre></div>

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p><a id="X7E90E6607F4E4943" name="X7E90E6607F4E4943"></a></p>

<h4>4.3 <span class="Heading">Symbols</span></h4>

<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

<h4>4.5 <span class="Heading">Keywords</span></h4

<p><em>Keywords</


<div
<span class="GAPprompt">gap></span> <span class="GAPinput">keys:=SortedList( GAPInfo.Keywords );; l:=Length( keys );;</pan
<span="GAPprompt>></pan><span class"GAPinputarr List(  0 .. ( l/4 )1 ] i-gt{ 4* + 14 ]});/span>
<spanclass=GAPprompt>/span>span="GAPinput">if lmod 4<gt0then Add arr,{[ 4*Intl4 + 1 . l }) fi;<span
<span="GAPprompt>&;/> <pan class""Lengthkeys) PrintArray(  )/>
35
[ [         Assert,           Info,        IsBound,           QUIT ],
  [TryNextMethod,Unbindandatomic
  [          break,       continue,             do,           elif ],
  [           else,          falsefi]
  [            for,       function,             if,             in ],
  [          local,            mod,            not,             od ],
  [             or,           quit,       readonly,      readwrite ],
  [            rec,         repeat,         return,           then ],
  [           true,          until,          while ] ]
</pre></div>

<p>Note that (almost) all keywords are written in lowercase and that they are case sensitive. For example <code class  [[            for,       function             if,              ],

<p><em>Note</em>: Several tokens from            ,         repeatreturn,           then ]

<p>Keywords <code class="code">atomic</code>, <<pre<>

<p>a id=X860313A179A5163F" ="X860313A179A5163F"></a>/p>

<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)

p  identifier a  functioncode=code><code>/>

<p>An identifier that starts with a 

<p>The

<

<h5>4<><a id"85CF993B7D19F2C4" nameX85CF993B7D19F2C4"></a></p>

<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>

<p><a id="X839A7F8E84BBCA57" name="X839A7F8E84BBCA57"></a></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.</>

<p><a id>The  rule stated inSection <ahref=./.docchap2_mj#X82F47EA88347AC2D< classRefLink: Variables Objects/></a>)/>

<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

<p>The simplest cases 


<ul>
<li><p>variables (

</li
<><> literals Section<ahref.#815F71EA7BC0EB6Fspan4./><>/

</li>
<li><p><li>

</li/>
<><pintegerliterals( Chapterahref=chap14_mj#X853DF11B80068ED5< classRefLink>4<span<a)<pjava.lang.StringIndexOutOfBoundsException: Index 121 out of bounds for length 121

</li
<lipfloatingpoint ( Chapter<a href"chap19_mj.#X81AA901181CA568F"><spanclass"19span<a>,/>

</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"">left-right<td
<span class="GAPprompt"tr
4
<span class="GAPprompt">gap></span> <span class="GAPinput">2 * 2 + 9 = Fibonacci(7) and Fibonacci(13) in Primes;</span>
true
</pre></div>

<p>The followingtr

<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

<p>For ="func">table""width%><>td"tdleft"><codeclass">#8227 </code> <var class="">name</var> )<td><td ="tdright&;unction)/>/>/>/iv

<p><a id="

<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>

<p>spanclass"gapgt<span>< ="APinput>("";/>

<p>Note that the functions <code class="func">

<p><a id="X7CD3523B84744EB2" name="X7CD3523B84744EB2"></a></p>

<>4.9- IsReadOnlyGlobal/>

<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>

<p><a id="X850CE44478254F27" name="X850CE44478254F27"></a></p>

<h5>4.9-2 MakeReadOnlyGlobal</h5>

<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>

<p><a id="X84BB4B1E872849FF" name="X84BB4B1E872849FF"></a></p>

<h5>4.9-5 ValueGlobal</h5>

<iv=""><table class"width"100%>tr<td =tdleft class">&8227 ValueGlobal</code> varclass"">name</var> )/td><td ="tdright(nbsp&;)/>/r<table>
<p>returns the value 

<>a ="X823D4BC378395B32" nameX823D4BC378395B32<a>/

<h5>4.9-6 IsBoundGlobal</h5>

<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

<p><a id="X7D39D3E17CF49F5B" name="X7D39D3E17CF49F5B"></a></p>

<h5>4.9-8 BindGlobaljava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#an style='color: green'>8227; BindGlobal</code>( <var class="Arg">name</var>, <var class="Arg">val functionreturnsan immutablesorted  ofthe global names createdsince thelibrarywasread,towhich   iscurrently bound<p
<divclass="unc"><table classfunc"width"%>tr class"dleft>codeclass"">‣ BindConstant</ode( <ar class="Arg<var var"">valvar>)/><td="tdright> function&;<td<tr>/table<div
<p><code class="func">BindGlobal</code> and <code class="func">java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

<p>This is intended to be the normal way to create and set <q>official

<p>Caution should


<div class="example"><div="">pre
<span class="GAPprompt">gap></span> <span class="GAPinput">xx := 16;</span>
16
<span class="GAPprompt">gap>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
false
<span class=GAPpromptgap;<spanspan="GAPinput">ValueGlobal"");</pan
16
romptgap/>< =GAPinput"IsBoundGlobal("xx;span
true
<span class="GAPprompt">gap></span> inearlier releasesof <trong=pkg</strong  <q></q>character class=code@code>wasalegal( using),this oflanguagenotbreak  code./>
#W BIND_GLOBAL
assgapspan =GAPinput;span
17
<spanclass=""gap/>span""IsReadOnlyGlobalxx";/span>
true
span">><span> span class"">MakeReadWriteGlobal("xx)</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">Unbind(xx);</span>
<

p =X876A6EB68745A510"A6EB68745A510></a></p>

<h5>4.9-9 NamesGVars</h5>p><code class="code>end</code></>

<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./>

<p><a id="X7E604AF579A7BC92" name="X7E604AF579A7BC92"></a></p>

<h5>4.9-10 NamesSystemGVars</h5>

<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

<p><a id="X870169447AF490D8" name="X870169447AF490D8"></a></p>

<h5>4.9-11 NamesUserGVars</h5>

<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,,8 13 21 34 55]

<p>For example, if the following is done in the


<div class class"&;/><spanclass"GAPinput>    n&;3then
<span class="GAPprompt">gap></span> <span class="GAPinput">a@ := 12;</spanclass;<span ="">fi>

pre

<p>Then actually the global variable <code class="code">a@xYz</<pre><div

<p>All other code outside the package

<p>Since in earlier<>The followingexample shows  waythat thefunction code=""></code (< ="chap21_mj.tmlX79975EC6783B4293">span class">.161<span></)   encoded anddemonstratesthe<qoptionalargument/>scenario</

<> ="X815F71EA7BC0EB6F"name"><a<pjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62

< ="GAPprompt">gt> < class"    localpos</pan>

<p>code="code>function( [<arclass"Argargident</var> , <var classArg-<var>}  )<code<p

<p><code class=<span classGAPprompt"&;/> <spanclass""    /span>

<p><code class="code">  span="GAPprompt">spanspanclassGAPinputfispan

<>code ="code">end></java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36

<p>A function literal can be assigned to a variable classGAPpromptgt/> <panclass"">      pos Length/span

<p>The following is an< class"&<class">;/>


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">fib := function ( n )</span>
<span="GAPprompt>gt;/span> spanclass=GAPinput>    f1 f2,f3 i;span
<span class="GAPprompt">></span> <span class="GAPinput">    f1 classGAPprompt>;</> <spanclass"   <span
<spanclass=GAPprompt&t;</> <span="GAPinput">     i in 3n </span
<pan=""&;/>< class="GAPinput"      f3 f1 f2span
<span class="GAPprompt">></span> <span class=2
<span="GAPprompt">&t;/> <span class=GAPinput"      f2 =f3<span
<span class="GAPprompt">></span
<span class=GAPpromptgtspanspan="GAPinput">return;<span
<spanclass"GAPprompt">&t;/span><pan
<span class="GAPprompt">gap></span> <span classThe example theq>any numberof arguments/>scenario./>
11235813213455 ]
</pre></div>

<p>Because for each of the<span classGAPinputlocal, x;/>


<div class="example"><pre>
< function n )/pan>
<span class="GAPprompt">></span> <span class="GAPinput">    if n < 3 then</span>
<span class="GAPprompt">></span> <span class="GAPinput">      return 1;</span>
<spanspan ="GAPprompt">&t;/> < classGAPinput       :=total<span>
span=GAPprompt&;/> <spanclass"       fib(-1  fibn-);/span>
<span class="GAPprompt">></span> <span class="GAPinput">    fi;</ class"">&;</span>< class"APinput"     totalspan
;</span
<span class="GAPprompt">gap></span> function l. ) . end
55 ]
</pre

<>Note thatthe recursive version  <codeclass="ode>2*fib<var class=Arg>n<var)1/code>  to compute< class="code>ibvar=Arg"n/>)</code,whiletheiterative versionof<code class="codefibcode needs< classcode"< class="Argn/ar>2/> steps Both are optimal,  libraryfunction<code="func></ode>(ahref"chap16_mj#AE1D70803A886C>span ="RefLink>.31<>/>    codeclass=code>(varclass""n/var>)</> steps<>

<p>As noted in Section <a href="chap4_mj.html#X78C70489791FDF43"10

<p>The following example shows one way that the function <code class="func">Position</code> (<a href="chap21_mj.html#X79975EC6783B4293"><span class


<div class="
<spanclass=GAPpromptgap;</> < class"GAPinput>position := function(list, obj, arg... )/span>
<span class="GAPprompt">
ompt;/panspan"GAPinput"    0=Lengththen
<span class
<span class="GAPprompt">></span> <pUsing the<code="code">../code  on function<varclass"Arg">f/var> with onlyonly asingle named argument  <strong="kg">GAPstrongthat itencountersvar"Arg"f<var>  itshould form list of arguments <var class=Arg"f/>    wishestodo  qopposite/>  strongclass"kg"GAP/> that a  should be <q>unwrapped</>andpassed as  arguments toafunction. The  <code class="func<code>< =chap5_mj.#X7CF4DDB97D65AE52span"RefLink">52-<span<a) is  for purpose<p>
<spanclass"GAPprompt>gt<span> <span class"GAPinputpos arg1]/pan>
<span class="GAPprompt">></span> <span class="GAPinput">    fi;</span>
<span class="GAPprompt">></span> <span class="GAPinput">    repeat</span>
<span="GAPprompt">gtspan < classGAPinputpospos+1<span
<span class="GAPprompt">></span> <span class="GAPinput">       return class="Arg">expr>; end></>
<span class="GAPprompt">></span> <span class="GAPinput">        return fail;</span>
<span class=GAPprompt>span< classGAPinputfispan
<span class="GAPprompt">></span
<span class="GAPprompt">>/panspan="GAPinput">    return;</>
<span class=
function
<spandiv class="xample"<>
2
<span class="GAPprompt">gap></span> <span class="GAPinput">position([142], class"GAPprompt"gap<spanspan=GAPinput"Sum ( [1..100],{x}&; x2 );<span>
fail
<span class"">gap><span<span="GAPinput">Sort(list, {xy}-&t; gt; y);
fail
</pre[5,3  2  ]

<> following demonstrates the<>ny numberof</q>scenario.</>


<div class="example"><pre>
<span class"gapgt<span spanclass""f: }-gt;2<span
<span class="GAPprompt">></span> <span class="GAPinput">    local total, x;</span classGAPpromptgap&;</> <spanclass"Print()</pan
<span class="GAPprompt">></span> <span class 2;
<span class="GAPprompt">></span> <span class="GAPinput">    for x in l do</span>
<span class
<span class="GAPprompt">>pThecodeclasscode"{code> <code ="code"><code    for functions withoneargument<p>
<span class="GAPprompt">></span> <span class="GAPinput">    return total;</span>
<span class="GAPprompt">></span> <span class
function.)..end
<span class="GAPprompt">gap></span class"gapgt</>< =GAPinput">Sum( [1.100]] x -gt^));/pan>
6
< class"gapgt;/pan>span class"">(1 ,3 )<span>
10
<span /re>/>
0
</pre></div>

<p>The user should compare the above with the 

<p>GAP<span classGAPpromptgap&;/span>< class="APinput>Stack := function()</span>

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>

<p><code class="code">{ <var class="Arg">arg-list class="GAPprompt"gtspan>< classGAPinputendspan>

<p>This is a shorthand for<<pan="GAPprompt">gt</span><spanclass">       return Remove stack) ;</pan>

<p><code class="code">function < class"">><spanspan ="GAPinput"    ;/>

<p>var ="Arg>-list</ar   ( )argumentlist.Anyarguments     validfora normalGAP functionis    includingvariadic arguments./>

<> 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
53321 ]
<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
2 3, ]
<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
<span pre/>
<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><a id="X78C70489791FDF43" name="X78C70489791FDF43"></a></p>

<h4>

<>aidX80B93A9C7E0A57F4 ="X80B93A9C7E0A57F4>/a>/p

<h5.12- <span="Heading>Function   </>/h5java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73

<p><code class="code"panclass">ap>/span> < class="APinput( );<span

<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/> = <var classArg<var)&;>( classArg<var var="">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"><var var="rg"b/ar= varclassArgc/var) and class">d<var><code></p>

<h5>4.12-2 <span class="Heading">Function Call With Options</span></h5>

<p< class"ode><ar class=Arg>function-var/>( <varclass"Arg"-expr/>, < class="Arg"-</> ..[:[ varclass"rgexprvar< =Arg-exprvar..])</>/>

<p>As well

< ="GAPpromptgap>/pan span class=GAPinput> * 2+ 9 =Fibonacci(7);<span>

<rue

<p>The following example shows


<div class< idX7B66C8707B5DE10A="X7B66C8707B5DE10A"<><>
<span class="GAPprompt">gap></span> <span class="GAPinput">Sizeh4414 <span class="Heading">rithmetic Operators/span></h4>
/>div

<


<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>-<>/><>

<p><em>Note>codeclass=">varclass"">left-expr</var  <var class="Argexpr<code/>

<p><a id="X7A274A1F8553B7E6" name="X7A274A1F8553B7E6"></a></p>

<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><code class="code"><var class="Arg">left-expr</var> = <var class="Arg">right-expr</var></code></p>

<codecode< =">-expr/> &;><var class"">right-expr</></code>/p>

<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 class="Arg">left-expr</var> <

<p><code class="code"><var class="Arg">left-expr</<p><code classcode>< class"avar /<varclass=Arg"><></> denotesmultiplication <var class=Arg</> with multiplicative inverseofvar="bvar./>

<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<var  var="">b</ar<varclass>/var<> for< =Argwherehave integers)pjava.lang.StringIndexOutOfBoundsException: Index 787 out of bounds for length 787

<p><code class=

<p> =""&t<code denotes, ="&;=code>  than orequal <code ="">&;</>  than,and <code ="code;/>greateror kind thethe>

<p>Note that <code class="code"><</code> implements a <em>total ordering</em> of

<p>Only for

<p>For other objects, <strong

<p>However

<p>Of

<p>Comparison operators, including the operator <code class="keyw">in</code> (see <a href="chap21_mj.html#X808A207182B2F84F"><span

<p>The following example shows



<
true
/<>

<p the operations ofthe introduced,see< href.html"< class""3111/>/>./>

<p><a id="X7B66C8707B5DE10A" name="X7B66C8707B5DE10A"></a>

<h4>4.14 <span class="Heading">Arithmetic Operators</span>p  arithmeticandthe operations  operatorsabove  =".html#X7A2914307963E370< class"">3112span/>/>

< =code class-</var>p

<p><code class class"GAP/> programs  of a sequenceof so-called em>statements</m. The following types of  exist:/>

<p><code class> see ahrefchap4_mjX7E6A50307F4D3FAE class".1/>/>,/p>

<p><code class="code"><var class="Arg">left/li

<

<<< class"<code statements (eeSection<ahref="chap4_mj">span ="".153/span></>)/>

<p><codejava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

<p><code class="code"><var class="Arg">left-expr<

p  operatorscode=code>/codecode 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<varvarArg><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 address users 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><p>Procedure calls (see 

</li>
<li><p><code class="keyw">if</code> statements< classGAPpromptgapgt<span < class"data:rec : [1,2   ;/>

<>
<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

</li>
<li> class>pre

/
<li><p><code classclassGAPprompt><span spanclassGAPinput:=function  return(  ;;;<span

<4
<>>code"></code  (seeSection < href="chap4_mjX812C6ABC7A182E9E>spanRefLink4159/pan.p>

</li>
</ul>
<p  readloop

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>hello


<class>
<span class="GAPprompt">gap></span> <span class="GAPinput">i := 7;;</span>
<span class="GAPprompt">gapgt;<span < classGAPinput> i lt k=/ ;<>
Syntax error
if;    16;;
                 ^
gap>
<>div

<p

<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><a id="X7E6A50307F4D3FAE ="examplepre

<h5>4.15-1 <span class< class="&/>< =GAPinput"l:1,2];/pan

<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


<div class
< class"&;</span> <span class="GAPinput:rec:[1,3 )/>
rec( numbers := [ 1
<span class="GAPprompt">gap></span> <span class="GAPinput">data.string:= "string";; data;</span>
recnumbers 1, ,3 ] string =string
<span class="GAPprompt">gap></span> <span class=
rec :[1,, ,string string
</pre></div>

<> 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>/>

<p><a id="X825803DE78251DA6" name

<h5>4.15-2 <span class="Heading">Procedure Calls</span></h5>

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


<div class="example"><pre>
<span class="GAPprompt">gappre<div
<span class="GAPprompt">gap>aidX87AA46408783383F=X87AA46408783383Fa<p
<span class="GAPprompt">gap></span> <span class="GAPinput">Append(<5415spanclassHeading</spanh5
</pre></div>

< 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< classGAPpromptgt;> <span="GAPinput">od;</span>

>   =keyw>statement  by<ode="">fi</code> keyword thereisno question where  <codeclass"elsecode  belongs .. strongclass="kg<strong qdangling/.In>


<div class="example"><pre>
if expr1 then
/><div

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""\1 22,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><a id="X87AA46408783383F" name="X87AA46408783383F"></a></p>

<h5>4.15-4 <span class="Heading">While</span></h5>

<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

<h5>4.15-5 <span class="Heading">Repeat</span></h5>

<p><code class="code">repeat <var class="Arg">statements</var> until <var class="Arg">bool-expr</var>;</code></p>

<p>The <code class="keyw">repeat</code> loop executes the class"GAPprompt"gap;<span <panclass"">s:=0<span

<p>First <var class=" class=GAPprompt>gt;/>< =GAPinput">    =s+i<span

<p>The difference between class>>> span""s<>

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,3 6 9 9]
204


<p>A <code class="keyw">repeat</code> loop may be leftdiv="example>pre>

<p< ="X78783E777867638A" name"X78783E777867638A"><a</

<5>4.15-< classHeading"></span></5java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48

<>code="code"for class"-/>invarclass="list<>  <var="">statements> odcode<p>

<p>The <code class="keyw">for</12    

<p>The statement]

<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>


<div class="example"><pre>
loop_list := list;
loop_index := 1;
while lt(loop_listdo
  variable := loop_list[loop_index];
  statements
  loop_index := loop_index + 1;
od;
</pre></div>

<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>


<div class="example"><pre>
<span class="GAPprompt">gap>
<span class="GAPprompt
<spanclass="GAPprompt"></span> <span="GAPinput">   Print( , "");/>
<span class="GAPprompt">></span> <
<span class="GAPprompt">></span> <span class="GAPinput">od; Print( "\n" );</span>
1 2 3 4 5 6 3 6 9 9
<span class="GAPprompt">gap></span> <span class="GAPinput">l;</span>
1234563699 ]
<<>

<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> : [1 2 , 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
1 2 3 4 5 6
<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>Finally, span"">;<spanspan="">fi;<span


<div4
<span class="GAPprompt">gap><p><a idX7CCBA2247AA366BD"name"X7CCBA2247AA366BD>/><>
Group([ (1,2,3,4,5), (1,2)(3,4)(5,6) ])
<span class="GAPprompt">gap></span> <span class="GAPinput">count := 0;; sumord := 0;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">for x in g do</span>
<span class="GAPprompt">></span> <span class="GAPinput">count := count + 1; sumord := sumord + Order(
<span="GAPprompt">ap&;</span><spanclass"GAPinput">countspan
120
<span class="GAPprompt">gap></span> <span class="GAPinput
471
</pre></div>

<p>The effect of</p>

<p><code class="code">for <var class="Arg">variable<spanclass"GAPprompt">gapgt/> <span classGAPinputg: Group((,23,1,2));/span>

<p>should thus normally be the same as</p>

<p><code class="code">for <var class="Arg">variable</var> in AsList(<var class classGAPpromptgtspan span="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>

<p><a id="X7CCBA2247AA366BD" name="X7CCBA2247AA366BD

<h5>4.15-8 <span class="Heading">Continue</span

<p><code class="code">continue;</code></p>

<p>The statement <code class="code">continue;</code> causes the rest of the current iteration of the innermost loop enclosing


<ivexamplepre
<span class="GAPprompt">gap></span> <span class="GAPinput">g := Group((1,2,3),(1,2)
Group([ (1,2,3), (1,2) ])
<panclass"GAPprompt">gap>/> <span class="GAPinput">for x  g dospan>
<span class="GAPprompt">></span> <span class="GAPinput">if Order(x) = 3 then</span
<span class="GAPprompt">></span> <span class="GAPinput">continue;</span>
<span class="GAPprompt">></span> <span class="GAPinput">fi; Print(x,"\n"); odjava.lang.StringIndexOutOfBoundsException: Index 116 out of bounds for length 88
()
(2,3)
(1,3)
(<p classfoot>generated by< href="://www.ath.wth-aachen.de/Frank.Luebeck/GAPDoc">GAPDoc2HTMLa>/>
</pre></div>

<</tml


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">continue;</span>
Syntax error: 'continue' statement not enclosed in a loop
</pre></div>

<p><a id="X812C6ABC7A182E9E" name="X812C6ABC7A182E9E"></a></p>

<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><code class="code">return <var class="Arg">expr</var>;</code></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>

<p><a id="X8732D9257FFCEA1B" name="X8732D9257FFCEA1B"></a></p>

<h4>4.16 <span class="Heading">Syntax Trees</span></h4>

<p>This section describes the tools available to handle <strong class="pkg">GAP</strong> syntax trees.</p>

<p><a id="X81558D66810BEA67" name="X81558D66810BEA67"></a></p>

<h5>4.16-1 SyntaxTree</h5>

<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>


<div class="chlinkprevnextbot"> <a href="chap0_mj.html">[Top of Book]</a>   <a href="chap0_mj.html#contents">[Contents]</a>    <a href="chap3_mj.html">[Previous Chapter]</a>    <a href="chap5_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="chap13_mj.html">13</a>  <a href="chap14_mj.html">14</a>  <a href="chap15_mj.html">15</a>  <a href="chap16_mj.html">16</a>  <a href="chap17_mj.html">17</a>  <a href="chap18_mj.html">18</a>  <a href="chap19_mj.html">19</a>  <a href="chap20_mj.html">20</a>  <a href="chap21_mj.html">21</a>  <a href="chap22_mj.html">22</a>  <a href="chap23_mj.html">23</a>  <a href="chap24_mj.html">24</a>  <a href="chap25_mj.html">25</a>  <a href="chap26_mj.html">26</a>  <a href="chap27_mj.html">27</a>  <a href="chap28_mj.html">28</a>  <a href="chap29_mj.html">29</a>  <a href="chap30_mj.html">30</a>  <a href="chap31_mj.html">31</a>  <a href="chap32_mj.html">32</a>  <a href="chap33_mj.html">33</a>  <a href="chap34_mj.html">34</a>  <a href="chap35_mj.html">35</a>  <a href="chap36_mj.html">36</a>  <a href="chap37_mj.html">37</a>  <a href="chap38_mj.html">38</a>  <a href="chap39_mj.html">39</a>  <a href="chap40_mj.html">40</a>  <a href="chap41_mj.html">41</a>  <a href="chap42_mj.html">42</a>  <a href="chap43_mj.html">43</a>  <a href="chap44_mj.html">44</a>  <a href="chap45_mj.html">45</a>  <a href="chap46_mj.html">46</a>  <a href="chap47_mj.html">47</a>  <a href="chap48_mj.html">48</a>  <a href="chap49_mj.html">49</a>  <a href="chap50_mj.html">50</a>  <a href="chap51_mj.html">51</a>  <a href="chap52_mj.html">52</a>  <a href="chap53_mj.html">53</a>  <a href="chap54_mj.html">54</a>  <a href="chap55_mj.html">55</a>  <a href="chap56_mj.html">56</a>  <a href="chap57_mj.html">57</a>  <a href="chap58_mj.html">58</a>  <a href="chap59_mj.html">59</a>  <a href="chap60_mj.html">60</a>  <a href="chap61_mj.html">61</a>  <a href="chap62_mj.html">62</a>  <a href="chap63_mj.html">63</a>  <a href="chap64_mj.html">64</a>  <a href="chap65_mj.html">65</a>  <a href="chap66_mj.html">66</a>  <a href="chap67_mj.html">67</a>  <a href="chap68_mj.html">68</a>  <a href="chap69_mj.html">69</a>  <a href="chap70_mj.html">70</a>  <a href="chap71_mj.html">71</a>  <a href="chap72_mj.html">72</a>  <a href="chap73_mj.html">73</a>  <a href="chap74_mj.html">74</a>  <a href="chap75_mj.html">75</a>  <a href="chap76_mj.html">76</a>  <a href="chap77_mj.html">77</a>  <a href="chap78_mj.html">78</a>  <a href="chap79_mj.html">79</a>  <a href="chap80_mj.html">80</a>  <a href="chap81_mj.html">81</a>  <a href="chap82_mj.html">82</a>  <a href="chap83_mj.html">83</a>  <a href="chap84_mj.html">84</a>  <a href="chap85_mj.html">85</a>  <a href="chap86_mj.html">86</a>  <a href="chap87_mj.html">87</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>

Messung V0.5 in Prozent
C=94 H=96 G=94

¤ 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.0.38Bemerkung:  ¤

*Bot Zugriff






Versionsinformation zu Columbo

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Anfrage:

Dauer der Verarbeitung:

Sekunden

sprechenden Kalenders