<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> we follows <!-- %% --> <!-- %W language.xml GAP documentation Martin Schönert --> java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 <!-- %% --> <!-- %% --> <!-- %Y Copyright 1990-1992, Lehrstuhl D für Mathematik, RWTH Aachen, Germany --> <!-- %% --> <!-- %% This file describes the &GAP; programming language. --> <!-- %% -->
<Chapter Label="The Programming Language">
<Heading>The Programming Language</Heading>
This chapter describes the &GAP; programming language. It should allow
you, in principle, to predict the result ofRefComparisons/ /,
to know what we are talking about, we first have to look more closely at
the process of interpretation and the various representations of data
involved.
<!-- %% The &GAP; language and its interpreter in the kernel were designed by --> <!-- %% Martin Sch{\"o}nert. -->
First we have the input to &GAP;, given as a string of <Sect="rocedureCalls"/>, <Ref Sect="If"/>, <Ref Sect="While"/>,
those characters enter &GAP; is operating system dependent, e.g., they
might be entered at a terminal, pasted with a mouse into a window, or
read from a file. The mechanism does not matter. This representation of
expressions by characters is called the <E>external representation</E> of the
expression. Every expression has at least one external representation
that can be entered to get exactly this expression.
<P/>
The input, i.e., the external representation, is transformed in a process
called <E>reading</E> to an internal representation. At this point the input
is analyzed and inputs that are not legal external representations,
according to the rules given below, are rejected as errors. Those rules
are usually called the <E>syntax</E> of a programming language.
<P/>
The internal representation created by reading is called either an
<E>expression</E> or a <E>statement</E>.
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 external representation,
in which case the reading would only need to check for errors.
It could be a series of machine instructions for the processor on which
&GAP; is running, in which case the reading would more appropriately
be called compilation.
It is in fact a tree-like structure.
<P/>
After the input has <Ref Sect="Repeat"/>, <Ref"or"> < Sect"unction">
<E>evaluation</E> or <E>execution</E>.
Later we will distinguish between those two terms too,
but for the moment we will use them interchangeably. The name
hints at the nature of this process, it replaces an expression java.lang.StringIndexOutOfBoundsException: Range [0, 67) out of bounds for length 54
value of the expression. This works recursively, i.e., to evaluate an
expression first the subexpressions are evaluated and then the value of
the java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Those rules are usually called the <E>java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 0
<P/>
The result of the evaluation is, not surprisingly, called a <E>value<ection Label"LexicalStructure"> <!-- % The --> <!-- % set of values is of course a much smaller set than the set of --> <!-- % expressions; for every value there may be several expressions that will -->Heading>exical Structure</Heading> <!-- % evaluate to this value. -->
Again the form in which such a Most input of &GAP; consists of sequences of the following characters.
represented internally does not matter. It is in fact a tree-like
structure again.
<P/>
The last process is called <E>printing</E>. It takes the value produced by
the evaluation and creates an external representation, i.e., a string of
characters again. What you </>
you. You can look at it, paste youListing<[CDATA[
write it to a file.
<P/>
Lets look at an example to make this more java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 41
following string of 8 characters
<P/>
<Listing><![CDATA[ 1 + 2 * 3;
]]
<P/>
&GAP; takes this external representation and creates a tree-]>/Listing>
internal representation, which we can picture as follows
<P/>
<Listing><![CDATA[
+It is possible to use other characters in identifiers by escaping
/ \ 11hem with , but we not recommend the use of this feature.
/ \ 23
]]></Listing>
<P/>
expression is then evaluated. To do this &GAP; first evaluates the
right subexpression <C>2chapter Ref ="trings and Characters"/>)
subexpressions 2 and 3. However they are and comments (see <Ref Sect="Whitespaces"/>) the full character set
own value, we say that they are<Section>
done, the rule for <C>*</java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
values of the two subexpressions, which in this case is clearly 6.
Combining this with the value of the left operand of the <C>+</C>, which isSection Label="Symbols">
self-evaluating, too, givesHeading>Symbols</Heading>
is then printed, i.e., converted into the external representation
consisting of the single character <CThe process of reading,i.., of assembling the input into expressions,
<P/>
this fashion can java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 73
java.lang.StringIndexOutOfBoundsException: Range [73, 9) out of bounds for length 73
that tell us for every expression how its ofsymbolsconsistsof ,
values .
The syntactic rules are given in sections <Ref Sect="Lexical<P/
<Sect=Symbols"> Ref ""><ef Sect=K">java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
and < =Identifiers>
the semantic rules are given in sections <Ref Sect="Expressions"-digit notakeywords<Sect"Identifiers"/>).
< =Variables> =Function ">
<Ref Sect="possibly prepended by <C>-</C> and <C>+</C> sign characters.
<RefSect"">,Ref =">,
<Ref quotes( Ref=Strings Characters/)
<Ref Sect="Repeat"/>, <Ref P>
java.lang.StringIndexOutOfBoundsException: Range [8, 3) out of bounds for length 54
]<Listing>
<P/>
,uppercaseand lowercase letters,<Space/> <TabB
<B>Newline</B>, <B>Returnalsothat ofscanning whitespace
<P/
<Listing><![CDATA[ " ' ( ) * +/>
. / : ; <
[ <!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
]]><<Label""
<P/>
t by
them with java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
Inside strings
(see section <Ref Sect="Symbols"/> and
chapter <Ref Chap="Strings and Characters"/>)
and comments (see <Ref Sect="Whitespaces"tabulator<Index>Index>newline</Index>
supported by the computer is allowed.
The process of reading, i.e., The characters <B>Space</B>, <B>Tab</B>, <B>Newline</B>, and <B>Return</B>
has <E>scanning</>,that the characters into
symbols. A <E>symbol</E> is a sequence of characters that form a lexical
java.lang.StringIndexOutOfBoundsException: Range [24, 4) out of bounds for length 68
integers, and operator and delimiter symbols.
<P/>
A <E>such as inte, identifiers, or keywords.For example
An<E>identifier</> a sequence of letters,digits and underscores
(or other characters /C> is the keyword <>or</K> between the two identifiers
non- and not a keyword (see <Ref Sect="Identifiers"/>).
An integer is a sequence of digits (see <Ref Chap="Integers"/> hitespace mayoccur between any two symbols, but not within a symbol.
java.lang.StringIndexOutOfBoundsException: Range [34, 8) out of bounds for length 60
A <E>string</E> is a sequence of arbitrary characters enclosed in
double quotes (see <Ref Chap=tpart from the role as separator of symbols,,
<P/>
Operator and delimiter symbols are
<P/>
<Listing><![CDATA[
+ - * / ^ ~ !.
= <> < <= > >= ![
:= . .. -> , ; [
] { } ( ) :
]]><Listing>
<P/>
Note also that during the process of scanning all whitespace is removed
(see <Ref Sect="Whitespaces"/>).
<Index>space</Index>
<Index>blank<Index<Index>abulator</Index><Index>newline</Index>
<Index>comments</Index><Index>#</Index>
The Inside a string, the comment character <C>#</C> loses its role and is just
are called<E>hitespace characters</E>.
Whitespace is used as necessary to separate lexical symbols,
such as integers,identifiers,or keywords.For example
<C>Thorondor</C> is a single identifier,
while <C> orondor<C>isthe keyword <>or<K between the two identifiers
<C>Th</C> and <C>ondor</C>.
Whitespace[DATA[
Two or more adjacent whitespace java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 31
whitespace.
Apart]</isting>
whitespace characters are java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 4
Whitespace a := -i; = # takeadditiveinverse
where they else#otherwise
Whitespace characters a := i; # take
<P/>
</Estarts thecharacter <><C,
which is sometimes called sharp
and java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 76
java.lang.StringIndexOutOfBoundsException: Range [41, 3) out of bounds for length 70
is treated as a single whitespace.
Insidestring,thecommentcharacter<#</C>losesitsroleandis java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
an ordinary character.
<P/>
For example, the following statement
<P/>
<Listing><![CDATAi0hena:-i;lsea;i;
if i<0 then a:=-i;else a:=i;fi;
]]></Listing>
</>
is equivalent to
<P/>
<>!CDATA[
if i < 0 then # if i is negative
:= -i; # take its additive inverse
java.lang.StringIndexOutOfBoundsException: Range [10, 4) out of bounds for length 27
a :=<Sectionjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
fi;
</
(which by the way shows that it is Section Label="
st statement is<>not/ to
<P/>
<Listing><![CDATA[
ifi<0thena:=-i;elsea:=i;fi;
]]></Listing>
</
since the keyword <
by a E>Keywords>arereservedjava.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 77
and orare partof statements Theymust beusedas identifiers The of
<E>Keywords</E> are reserved words that are used to denote special <>GAPInfo<C>record(ee RefSect=G">.We will show how print
or of statements usedas identifiers Thelistof
keywords is contained:
<C>GAPInfo</P>
it in a nice<><C[
techniques:
<P/>
<Example><![CDATA[
gap> keys=SortedList(GAPInfoKjava.lang.StringIndexOutOfBoundsException: Range [40, 39) out of bounds for length 63
gap> arr:= List([ 0..(l4)-] i>keys 4i [1. 4] });
gap> if l mod 4 <> 0 then Add( arr, keys{[ 4*Int(l/4) + 1 .. l ]} ); fi;
gap> Length( keys ); PrintArray( arr ); 35
[ [ Assert, Info, java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 39
[ TryNextMethod, Unbind, and, atomic ],
[ [ ,Unbind, , ],
[ else, end, false, [ break, continue, do, elif
[ for, function, if, in ],
[ local, mod, not, od ],
[or, quit readonly, ]
[ rec, repeat, return, then ],
[ true, [ rec, repeat ],
]]></Example>
<P/>
Note that (almost) all keywords are written Note that (lmost keywords arewritten lowercase and that
are casesensitive
For example <For <else/K akeyword <Else<> C>LsE/,<ELSE<Cjava.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
Keywords notcontainwhitespace forexample <> if/>is not the
Keywordssameas K></>
same as <K>elif<//
<P/>
<NoteE>
Several tokens tokens thelist of keywords above may appearto be normal
identifiers functionsor various kinds but are
actually implemented as keywords for technical reasons. actually implemented as keywords for technical reasons. The only
consequence of this consequence of this is that those identifiers cannot be re-assigned, and
java.lang.StringIndexOutOfBoundsException: Range [43, 2) out of bounds for length 67
assigned to other variablesassigned other variables or to .These
<</><K>false</> Ref Func"ssert"/>,
<Ref Func="IsBound" Label="for a global variable"/>,
<Ref Func="Unbind" Label="unbind a variable"/>,
<Ref Func="Info"/> and <Ref Func="TryNextMethod"/>.
<P/> <!-- Update the next paragraph to reference HPC-GAP suitably -->
Keywords <C>atomic</C>, <C>/,<readwrite/ not
at the moment. They are reserved for < Func=IsBound "ora global ">
identifiersjava.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
<>
An<>identifier</E> is used to refer to a variable
(see <Ref Sect="Variables"/>).
An identifier usually consists of letters, digits, underscores <C>_</C>,Keywords Catomic/C>,<></> C><C>are notused
and <Q>at</Q>-characters <C>@</C>,
and must contain at least one non-digit.
java.lang.StringIndexOutOfBoundsException: Range [16, 2) out of bounds for length 69
Note that the <Q>/Section>
namespaces
<P/>
java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 33
<P/>
<>!CDATA[
a foo aLongIdentifier
hello Hello HELLO
_00
java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 30
WePreferMixedCaseToSeparateWords
abc@def
]]></Listing>
<P/>
Note that caseissignificant threeidentifiersin second
line are distinguishedand mustcontain at least one non-digit.
<P/>
java.lang.StringIndexOutOfBoundsException: Range [13, 3) out of bounds for length 78
a backslash followed by a character is equivalent to the character,
this is .
For example
<<[java.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 18
GEofvalid
]]></java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 4
is an identifier,not call to a function <C>G<C.
<P/>
An identifier that starts with a java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
example <C>\*</C> and <ello Hello HELLO
<java.lang.StringIndexOutOfBoundsException: Range [3, 2) out of bounds for length 4
The length of identifiers is not limited,
however only the first <WePreferMixedCaseToSeparateWords
The escape sequence <C>\</C><B>java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 7
making it possible to split long identifiers over multipleP/java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
<#Include Label="IsValidIdentifier">
Note that the <>t/>-characteris usedto implement namespaces
for global variables in packages. See <Ref Sect="Namespaces"/> java.lang.StringIndexOutOfBoundsException: Range [0, 66) out of bounds for length 4
details.
<Index>namespace</Index>
<Subsection Label="Conventions about Identifiers">
<HeadingConventions about Identifiers</Heading>
<Index>variable names</Index>
( Section
<Ref Sect="Variables versus Objects" BookName="tut"/>.)
</
henameof almost every global variable in the &AP;library
]]</Listing
(See an identifier not a call to a
For user variables, we identifier that starts with isnevera keyword,so for
<lowercase <>in toavoidname .
<P/>
For example &AP;inputwhichsome user variableswhosenames
start with however only the first <M>1023</M> characters are significant.
or inescape sequence<>\/>B>newline<B isignored,
because because ittosplit identifiersover multiplejava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
in this situation.
</Note that the <Q>at</Q>-character is used to implement namespaces
<Index>evaluation</Index>
An <E>expression</E> is a construct that evaluates to a value.
Syntactic are and
no value are called <E>statements< Sect="versus =t/.)
Expressions appear as right hand sides of assignments
(see <Ref Sect="Assignments"/>), as actual arguments in function calls
(see <Ref Sect="Function Calls"/>), and in statements.
<P/>
Note that an expression is not
For example <111<C> is expression, whosevalue the integer 12java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
java.lang.StringIndexOutOfBoundsException: Range [60, 3) out of bounds for length 69
<C>12</C>, i.e., this sequence in &GAP packagesstartswith <>apitalletter/>java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
E> nameclashes
The process of finding the value of an expression
and is called the <E>evaluation
<P/>
The simplest cases expressions are following
<List>
<>variables(ee Sectionn;Ref Sect=Variables/>,/>
<Item>function literals (see or in a &GAP; session with more or newer packages,
<Item>function calls (see Section becauseit thesevariables predefined variables
erals(ee Ref Chap=Integers/)/java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
<>loatingpointliterals s Chapter <efChap=Floats/)<Item>
<Item>permutation literals (
<Section
<Item>characterjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
<Item>list literals (see Chapter Section =Expressions>
<Item>record literals (see Chapter <Ref Chap="Records"<eading>xpressionsHeading
</List>
Expressions,for example the simpleexpressionsmentionedabove be
combined with the An <E>expression</E> is a construct that evaluates to a value.
those expressions can then be combinedfurther theoperatorsto form
evenmorecomplex expressions <><E fall intothree classesjava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
<Index>operators</Index>
java.lang.StringIndexOutOfBoundsException: Range [18, 3) out of bounds for length 77
<C>></C>, <C>>=</C>, and <K>in</K> (see <Ref Sect="Comparisons"/> s < Sect"Calls">, statementsjava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
<Ref Sect="Membership Test for Collections"/>).
The <E>arithmetic operators</E> are <C>+</C>, <C>-</C>, <C>*</C>, <C>/</C>,
<K>mod</K>, and <C>^</C> (see <Ref Sect<>2/> .. sequence isoutputif theinteger printed
The <E>logical operators</E> are <K>not</K>, <K>and</K>, and <K>or</K>
(see <Ref Sect="Operations for Booleans"/>).
<P/>
java.lang.StringIndexOutOfBoundsException: Range [13, 3) out of bounds for length 71
more complex expression.
<P/>
<Example><![CDATA[
gap> 2 * <> 4
in Primes;
true
]]>List>
<P/>
The following table lists all operators by precedence, from highest to
java.lang.StringIndexOutOfBoundsException: Range [34, 6) out of bounds for length 72
left-to-right) or right associative (aka right-to-left) or neither.
<Index>precedence</Index>
<java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
<Table Align="ll">
<Row>
<ItemItem> literals (see Chapter <Ref Chap="Permutations"/>),</Item>
<Item>/E></tem>
</Row>
<HorLine/>
<Row>
<Item><E>arithmetic (see <Ref Sect="Item>list literals (see Chapter <Ref Chap"),and</tem
<Item
<Row>
<Row>
<Item> <C>^</C></Item>
<Item>none</Item>
</Row>
<Row>
<Item> unary <C>+</C>, unary <C>-</C></Item>
<Expressions the ,be
</Row>
<Row>
<Item> <C>*</C>, <C>/</C>, <K>mod</K></Item>
<Item>left-to-right</Item>
</Row>
<Row>
<tem>nbsp;binary <+/C,binary <>-/>/Item>
<Item>left-to-right</Item<ndex>operators/Index
</Row>
<HorLine/>
<Row>
<Item><E>comparison (see <Ref Sect="Comparisons"/>)</C><C>, C><C,and <>n/K>(see <Ref ="omparisons"> and
<Item></Item>
<Row>
<Row><K, ><>(nbspRef= /.
<Item> <C>=</C>, <C><></C>, <C><</C>, <C><=</C>, <C
<Item></Item>
</Row>
<HorLine/>
<Row>>
<Item><E>logical (see&java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 24
<Item></Item>
<Row
<Row>
<Item> <K>not</K>gap 2+ and Fibonacci13 inPrimesjava.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
<Item>right-to-left</Item>
</Row>
<P/
<Item> &java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 0
<Item>left-to-right</Item>
</Row>
<Row>
<Itemlowest,and also indicateswhether the operatoris left associative (ka
<-to-ight/
</
<java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 10
<Index>scope</Index><Index>bound</Index>
inG a.
We say the variable is <E>bound</E> to this value.
If a variable is evaluated it evaluates to this value.
<P/>
Initially an ordinary variable is not bound to any value.
The variable can be bound to a value by <E>assigning</E> this value to the
variable (see <Ref Sect="Assignments"/>).
Because of this we sometimes
value has no assigned value.
Assignment is in fact the <java.lang.StringIndexOutOfBoundsException: Range [6, 5) out of bounds for length 6
argument of a function, can be bound to a value.
After a variable has been bound to a value an assignment can also be used
to bind the variable to another value.
<P/>
A special class of variables is the class of <E>arguments</E> of functions.
They behave similarly to other variables,
except they are bound to the value of the
actual arguments upon a function call (see <Ref Sect="Function Calls"/>).
<P/>
Each variable has a name that is also called its <E>identifier</E>. This is
because in a given scope an identifier identifies a unique variable (see
<Ref Sect="java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 19
A <E>scope</E> is a lexical part of a program text. There is
the <E>Row
local scopes ;;nbsp&unaryC+/C>unary<C><>/java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
beginning of a function definition, to the corresponding <K>end</K> keyword.
A <E>local scope</E> introduces new variables, whose identifiers are given in
the formal argument list and the <K>local</K> declaration of the function (see
<Ref Sect="Function"/>). Usage of an identifier in a program
the hasidentifierasits name.
Because this mapping from identifiers to variables is done when the
program is read, not when it is executed, &GAP; is said to have <E>lexical
scoping</E>. The following example shows how one identifier refers to
different variables at different points in the program text.
<P/>
<Listing><![CDATA[
g <tem>nbsp&bsp; nbsp;C>/> C>/<C>,<java.lang.StringIndexOutOfBoundsException: Range [61, 58) out of bounds for length 69
x := function ( a, b, c )
local y;
g := c; # c refers to argument c of function x
y := function ( y )
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 g
return d + e + f;
end;
return y( a ); # y refers to local y of function x
end;
]]></Listing>
<P/>
It is important to note that the concept of a variable Itemnn;nbsp&;inaryC>+C,binary<>-/>/
different from the concept of a variable in most compiled programming languages.
<P/>
In those languages a variable denotes a block of memory. The
value of the variable is stored in this block. So in those languages two
variables can have the same value, but they can never have identical
java.lang.StringIndexOutOfBoundsException: Range [8, 6) out of bounds for length 66
some languages have the concept of a reference argument. It seems as if such an
argument and the variable used in the actual function call have the same
value, since changing the argument's value also changes the value of the
variable/ow>
reference argument is actually a pointer to the HorLine/
actual function call, and it is Row>
make the pointer invisible. In order for this to Item> (see&;Ref Sect"Comparisons"/>)</E></Item>
needs enough information to compute the amount of memory needed for each
variable in a program, which is readily available in the declarations.
<P/>
In &GAP; on the other hand each variable just points to a value,
and different variables can share/ow>
<<Item&bsp; <C>=</C>, <C><></C>, <C><</C>, <C><=</C>, <C>></C>, <C>>=</C>, and <K>in</K></Item>
<java.lang.StringIndexOutOfBoundsException: Range [19, 5) out of bounds for length 64
<Description>
<Ref Func="IsBound" Label="for a global variable"/> returns <K>true</K>
if the variable <A>ident</A> points to a value,
and <K>false</K> otherwise.
<P/>
For records and lists <Ref Func="IsBound" Label="for a global variable"/>
can be used to check whether components java.lang.StringIndexOutOfBoundsException: Range [1, 42) out of bounds for length 10
are E(;java.lang.StringIndexOutOfBoundsException: Range [50, 33) out of bounds for length 78
(see Chapters <Ref Chap="Records"/> and <Ref Chap="Lists"/>).
</Description>
</ManSection>
<ManSection>
<Func Name="Unbind" Arg='ident' Label="unbind a variable"/>
<Description>
deletes the identifier <A>ident</A>.
If there is no other variable pointing to the same value as <A>ident</A> was,
this value will be removed by the next garbage collection.
Therefore <Ref Func="Unbind" Label="unbind <>
ofjava.lang.StringIndexOutOfBoundsException: Range [16, 15) out of bounds for length 30
<P/>
For records and lists <Ref Func="Unbind" Label="unbind a variable"/>
can be used to delete components or entries, respectively
(see Chapters <Ref Chap="Records"/> toleft/>
</Description>
</ManSection>
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="More About Global Variables">
<HeadingMore AboutGlobal Variables</Heading>
The vast majority of variables in &GAP; are defined at the outer
level (the global scope). They are used to access functions and
other objects created either<Row>
code.
<P/>
Note that for packages <Item>  or<K<Item>
namespaces on top of this global namespace. See Section <Ref
Sect="Namespaces"/> for details.
<Indexnamespace</Index>
<P/>
Certain special facilities are provided for manipulating global
variables which are not available for other types of variable (such as
local variables or function arguments).
<P/>
First, such variables may be marked <E>read-only</java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 0
<Ref Func="MakeReadOnlyGlobal"/>. In which case
attempts to change them will definedinthe&GAP;libraryaresomarked.<=> bemade-writeagainbycalling<RefFunc="MakeReadWriteGlobal"/>.
java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 73 <RefFunc="MakeConstantGlobal"/>.Constantvariablescanneverbejava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 optimisecodewhichuses<E>constant</E>variables, astheirvalueneverchanges.InthisversionGAPtheseoptimisationscanbe observedbyprintingthefunctionbackout,butthisbehaviourmaychange inrangethe<function/>,denoting <Example><![CDATA[ gap>globali:=1+2;; gap>globalb:=true;; gap>MakeConstantGlobal("globali"); gap>MakeConstantGlobal("globalb"); gap>f:=function() >ifglobalbthen >return >else >globali+2java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 ; >(java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 gap(; function() returnf:=g;referstoglobalvariablejava.lang.StringIndexOutOfBoundsException: Range [45, 46) out of bounds for length 45 end Example>
<P/> functionsaresuppliedforaccessingandthe valuesassignedvaluethevariablestoredinthis.Sothoselanguagestwo theofassignment, <Func=uvariable">and <RefFunc="IsBound"Label="foraglobalvariableargumentisathe statements,intwoways. First,thesefunctionsIn&APontheotherhandeachvariablejustpointstoavalue, localvariablesofthesamejava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 27
java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 49 ratherthanbeing;Chap=/RefChap"" <P/> Notethatthefunctions<RefFunc="NamesGVars"/>, <Func="amesSystemGVars"/>,and<RefFunc="NamesUserGVars"/>, dealwiththe<E>globalnamespace</E>.
<ManSection> "IsReadOnlyGlobal"Arg=name'/
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13 returns<K read-onlyand<K>false</ </Description> </ManSection>
<Description markstheothercreatedeitherinthe&AP;librarypackagesorintheuser'java.lang.StringIndexOutOfBoundsException: Range [78, 79) out of bounds for length 78 </> is<name<>valueifis alreadyread-to.ofthevariables </Description> <ManSection>
somecanwhichE></, =''
<Description:=; marksglobalthethe<></write <P/> Awarningisgivenif<A>name</A>isalready>Print()java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
<Log><![CDATA[ gap>xx:=17; 17 ()java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28 false gap>xx:=15; 15 gapMakeReadOnlyGlobal("x"; gap>xx:=16;
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 27 notinanyfunction Enteringbreakread-val-printloop.. youcanquit;toquittoouterloop,or youcan'return;'aftermakingreturnsK>true<K>iftheglobalvariablenamedbythestring<A>name</A>is brk>quit; "") true gap>MakeReadWriteGlobal gap>xx:=16 16 gap>IsReadOnlyGlobal false ]]></Log> </Description> </java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 4
<#IncludeLabel="MakeConstantGlobal>")
<ManSection <FuncName="ValueGlobal"<>xx=16
<Description> returnsthevaluecurrentlyboundtotheglobaljava.lang.StringIndexOutOfBoundsException: Range [57, 56) out of bounds for length 69 string<A>name</A>.Anerrorisraisedifnovalueiscurrentlybound. </java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 12 </ManSection>
<Description> returns<K>true</K>ifacurrently
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0 </Description> </ManSection>
<anSection> <FuncName="UnbindGlobal"Arg='name'/>
<Description> removesanyvaluecurrentlybound totheglobalvariablenamedbythestring<A>name</A>.Nothingisjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 0 <P/> A>name</A>wasboundglobalvariable by<A>name</A>mustbewritable,otherwiseanerrorisjava.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 0 </Description> />
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Namespaces">
<Heading>Namespaces for &GAP; packages<<the does notbreak any old code.
As mentioned in Section <Ref Sect="More About Global Variables"/>
above all global variables share a common namespace. This can
relatively easily lead to name clashes, in particular when many
&GAP; packages are loaded at the same time. ToHeading>Function/Heading>
a way to have a package local namespace without breaking backward
compatibility of the &GAP; language, the following simple rule has
been devised:
<Ind Key=local><>ocal<</>Index>
If in package code a global variable that ends with an
<Q>at</Q>-character <C>@</C> is accessed in any way, the name of the
package is appended before accessing it. Here, <Q>package code</Q>
refers to everything which is read with java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 43
entry <<C> in its
<F>PackageInfo.g</F> file is taken. As for all identifiers,
this name is case<C>nbsp;nbsp;local A>loc-ident/>{ <>-ident/> ]/C>
<P/>
For example, if the following is done in the code of a packageC nbsp;<A>statements</A></C>
<C>xYz</C>:
<Log><![CDATA[
gap> a@ := 12;
]]>
</Log>
Then actually
accesses to <C>a@</C> within the package code will all be redirected
to <C>a@xYz</C>. This includes all the functions described in Section
<Ref Sect="More About Global Variables"/> and indeed all the functions
described Section <Ref Sect="Global Variables in the Library"/> like
for example <Ref Func="DeclareCategory"/>. Note that from code/java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
possibleaccess same same global variable
via <C>a@xYz</C> explicitly.
<P/>
All other code outside the package as well as interactive user input
that wants to refer to java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 22
by using <C>a@xYz</C>.
<P/>
Since in earlier releases >end;
was not a legal character (without using backslashes), thisgap ([.10,)
xtension language not break any old code.
<Index Subkey="definition of">functions</Index>
<Index Key="end"><K>end</K></Index>
<Index Key="local"><Thisisusually called <>ecursion/>
<Index>recursion</Index>
<Index Subkey="recursiveg>fib := function ( n )
<Index>environment</Index><Index>body</Index>
<C>function( [ <A>arg-ident</A>
<P/> returnfib(n1 +fib(-2);
<C> [local <A>loc-ident</A> {, <A>loc-ident</A>} ; ]</C>
<P/>
<C> <A>statements</A></C>
<P/>
<>end/>
<P/>
A function
literal can be assigned to a variable or to a list element or a record
component.
Later this function can be calledcomputeC<<)C>
<P/>
The Index Key""pecialargument>>arg/>Indexjava.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
ofthe (<FuncFibonacci/java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
</>
<Example><![CDATAarguments.Thevaluesof the actual arguments are computed and the
gap> fib := function ( n )
> local f1,f2,f3,i
> f1 := 1; f2 := 1;
> for i in [3..n] do
> f3 := f1 + f2;
>
> f2 : java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
> od;
> return f2;
> end;;
gap> List [..0, fib );
[ 1, 1, 2, 3, 5, 8, 13, 21,Thefollowing example shows oneway that thefunction
]]></Example>
<P>
BecauseP/
locals <>loc-identA a new variable is allocated when the function
java.lang.StringIndexOutOfBoundsException: Range [24, 2) out of bounds for length 45
itis possiblethat function calls itselfjava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
This is usually called <E>recursion</E>.
The following is a recursive function that computes values of the Fibonacci
sequence.
<P/>
<Example><![CDATA[
ib: function (n )
> if n < 3 then
> else
> return fib(-) +fib(-2)
> fi;
> end;;
gap> List( [1..10], fib );
[ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ]
]>/Example>
<P/>
Note thatgap>(1,4,] )
to compute <C>fib(<A>n</A>)</C>,
while the iterative version of <C>fib</C> needs only <C><A>java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
Both are not java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
only needs about <C>Log(<A>n</A>)</C> steps the<anynumber <>
<P/>
<Index Subkey="with a variable Example<[java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
<java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 70
As noted in Section <Ref Sect="Function Calls"/>,
java.lang.StringIndexOutOfBoundsException: Range [19, 20) out of bounds for length 19
It provides a way java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 9
arguments. The values of the actual arguments are computed and the
firstones are assigned to the new variables corresponding to the
formal arguments before the last argument, if any. The values of all the
remaining actual arguments are stored in a list
and thislist assigned to the new variable corresponding to the finalformal
argument. There are two typical scenarios for wanting such a
possibility: having optional java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
arguments.
<P/>
Thefollowing exampleshows one way that the function
<Ref Oper"osition">mightbe encodeddemonstrates the
<Q>optional argument</Q> scenarioaninitial element (which zerojava.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 72
<P/>
<Example><![CDATA[
gap> position := function ( list, obj, arg... )
> local pos;
> if 0 = Length(arg) then
> pos := 0;
> else
> pos := arg[1];
> fi;
> repeat
> pos := pos + 1;
ngthlist) then
> return fail;
> fi;
> until list[pos] = obj;
> return pos;
> tell &AP that a list be<Qunwrapped</Q> and passed as several
function( list, obj, arg... ) ... end
gap> position([1, 4, 2], 4); 2
gap> position([1, 4Chapter;Chap"java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 46
fail
gap>position[,4,2] ,2);
fail
]>/xample
<P/>
The following example demonstrates the <Q>any number of arguments</Q>
scenario<>
<P/>
<Example><![CDATA[
gap> sum := function ( l... )
> local total, x;
> total := 0;
ldo
> total .
> od;
>return;
> end<>
function( l... ) ... end
gap>sum1 ,3); 6
gap> sum(1, 2, 3, 4); 10
gap> sum(); 0
]/>
<>
The user should compare the above with the &GAP; function <Ref Func="Sum"/>
which, for example, may take a list argument and optionally
an initial( java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
<P/>
GAP will also special case a function with a single argument with
<C>arg</C> as function with a variable length list of arguments, as <>
user C>.<C>
<P/>
Note that if a function <><[DATA[
then <>NumberArgumentsFunctionA><A)</C> returns
minus the number of formal arguments (including the final argument)
(see <Ref Oper="NumberArgumentsFunction"/>).
</
Using the <C>...</C> notation on a function <A>f</
named argument tells &GAP; that when it encounters <A>f</A> that itWhen the definition of a function <fun1<A is evaluated inside another
form a list out of the arguments of <A>f</A>.
What if one wishes to do the <Q>opposite</Q>:
tell &GAP; that a list should be <Q><Q and passedas
arguments to a function.
The function<RefOper=CallFuncList"/ provided purpose.
/
java.lang.StringIndexOutOfBoundsException: Range [16, 4) out of bounds for length 46
<>
<Index The interesting here isthat the functions <>push<C> and <C></>
<Index>arrow notation for functions</Index>
<C>{ <A>arg-list</A> } -> <A>expr</A></C>
<P/>
This is a shorthand for
<P/>
<C>function ( <A>arg-list</A> ) return <A>expr</A>; end.</C>
<P/>
<arg-list/A> empty)argument list.Any arguments list
which would be<>tackC>bound this .
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 20
<P/>
The following gives a couple of examples of a typicalP>
<P/>
<Example><![CDATA[
gap> Sum( List( [>stack=[; 338350
gap> list := [3, 5, 2, 1, 3];;
gap> Sort(java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
gap> list;
[ 5, 3, 3, 2, 1 ]
gap> f := {x,y...} -> y;;
gap> f(1,2,3,4);
[ 2, 3, 4 ]
gap> f := {} -> 2;
function( ) gap> A. 1) Apush
gap> Print(f);
function ( )
return 2java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
end
gap> f(); 2
]>/Example>
<P/>
The <C>{</C> and <C>}</C> may be omitted
functions with one argument:
<Example><![CDATA[
gap> Sum( List( [1..100], {x} -> x^2 ) ); 338350
gap> Sum( Listnotvery efficient. 338350
]]></Example>
<P/>
When the definition
function <A>fun2</A>,
&GAP; binds all the identifiers inside the function <A>fun1</A> that
are java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
variable.
This set of bindings is called the environment of the function <A>fun1</A>.
When <A>fun1</A> is called, its body is executed in this function-<A> [Aarg-expr/>,<A>rgexpr</A>, ...]] )</C>
The following implementation of a simple stack uses this.
Values can be pushed onto the stack and then later functionjava.lang.StringIndexOutOfBoundsException: Range [18, 17) out of bounds for length 77
The interesting thing here is that the functions <C>push<P/
in by <C></C>access the local variable Cstack<<C>
of <C>Stack</C>.
When <C>Stack</C> is called, a new variable for the identifier <C>stack</C>
is created.
java.lang.StringIndexOutOfBoundsException: Range [52, 4) out of bounds for length 68
evaluated (as part of the <K>return</K> statement) each reference to
<C>stack</C> is bound to this new variable.
Note also that the two stacks <C>A</C> and(eeChapter&bsp<RefChap="">)
because each call of <>tack</>createsa variable for C></C>java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74
<P/>
<Example><![CDATA[
gap> Stack := function()
> stack;
> stack := [];
> return rec(
> push := function( value )
> Add( stack, value );
> end,
> : function()
> return Remove( stack) ;
>IndexKey="rg" Subkey=special function argument,calling with">C></><Index>
> );
> end;;
gap>the <> <> definition.
=(java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
gap> A.push( 1 ); Awhichis argument
gap push4 ;B.push(5) .ush ;
gapactual arguments Ebefore 3 2 1
gap> P> 6 5 4
]]><thatvariableis ina G
<P/>
This feature that points to a vaThus and
not .
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> corresponding to the formal arguments. Of
<Section Label="Function Calls">
Heading Calls/>
<Subsection Label="Function Call With Arguments">
<Heading>Function Call With Arguments</Heading>
<-expr</>,A>rgexpr<> .] <C>
<P/>
The function call has the effect of calling the function <A>function-var</A>.
The precise semantics are as follows.
<P/>
First &GAP; evaluates the <A>function-var</A>.
Usually <A>function-var</A> is a variable,java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 48
java.lang.StringIndexOutOfBoundsException: Range [4, 3) out of bounds for length 67
It assignedthem anerrorjava.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
such as a reference to an element of a list
("Lists"/)
<C><A>list-var</A>[<A>int-expr</A>]</C>,
or to a component of a record (see Chapter <Ref Chap="Records"/>)
<C><A>record-var</A>.<A>ident</A></C>.
In any case &GAP; tests whether the value is a function.
If it is not, &GAP; signals an error.
<P/>
<ndex Subkey"of arguments,java.lang.StringIndexOutOfBoundsException: Range [61, 59) out of bounds for length 78
<Index Key=arg"Subkey="special function argument, calling with"><C>arg</C></Index>
Next &GAP; checks that the number of actual arguments <java.lang.StringIndexOutOfBoundsException: Range [0, 56) out of bounds for length 37
with the number of<>formal arguments</>as given inthe functiondefinition.
If they do not agree &GAP; signals an error.
has ,
which is denoted by adding <K>return</K> statement without an expression is executed, execution of the
In this case there must be at least as many
actual arguments as there are formal arguments <E>before the
final /> be larger
(statement java.lang.StringIndexOutOfBoundsException: Range [53, 52) out of bounds for length 71
<P/>
Now &GAP; Example><![CDATA
(that is, the identifiers in the <K>local</K> declaration) a new variable.
Remember that a variable is a location in a &GAP; program
that points to a value. Thus for each formal argument and for each
formal local such a location is allocated.
<P/>
Next <arg-xpr<Asareevaluated fromlefttorightjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
and the values are java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 14
to the newly G ;
coursethe first assigned to java.lang.StringIndexOutOfBoundsException: Range [71, 72) out of bounds for length 71
the first formal/>
variable corresponding to the second formal argument, and so on.
An argument has
the name <C>arg</C>. Heading CallOptions</Heading>
arguments not assigned to the other C><A>function-var</A>( <A>arg-expr</A>[, /> ..]:[<optionexpr/ ...]])/>
stored in a list and this list is assigned to the new variable
corresponding to the formal argument <C>arg</C>.
<P/>
The new variables corresponding to formal localsare initiallynot
bound to any valuesuggesting java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 63
something has been assigned to them will signal an errorq randomjava.lang.StringIndexOutOfBoundsException: Range [62, 61) out of bounds for length 66
<P/>
the,whichisastatement .
identifier of one of the formal /E> using the options .
bodyof the function it refersto the new variable that was allocated for
formaljava.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 72
variable.
>
If during the execution of the body ofP/
with java.lang.StringIndexOutOfBoundsException: Range [21, 11) out of bounds for length 91
is executed, execution of the body is
terminated and the value of the function call is the valueThe followingexample showsa call to < Attr=Size">passing the
java.lang.StringIndexOutOfBoundsException: Range [27, 10) out of bounds for length 70
< withoutexpressionisexecuted ofthe
body is terminated <>
which case we call this call a procedure call (see <java.lang.StringIndexOutOfBoundsException: Range [0, 55) out of bounds for length 14
If the execution of
statement, the function call againOptionswithcalls way are passeddown using
about a procedure call.
<P/>
<Example><![CDATA[
gap> Fibonacci( 11 ); 89
]>/Examplejava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
<P/>
The above example shows a call >>
actual argument <C><NoteE option passed any function,whetheror not
<java.lang.StringIndexOutOfBoundsException: Range [22, 4) out of bounds for length 69
functioncall.
<P/>
<><[[
gap> java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 10
]]></Log>
</Subsection>
<Subsection Label="Function Call With Options">
<Heading>Function Call With Options</Heading>
<C><A>functionC>Aleft-expr<A>=<>rightexpr</A></C>
<P/>
As well as passing arguments to a function
inputto calculation, it is sometimes useful to supply <Q>hints</Q>
suggesting to &GAP; how the desired result may be computed operator <></> testsfor equality of its two operands and evaluates to
quickly specifying levelof tolerance for randomerrors in a
Monte Carlo algorithm.
<P/>
Such hints may be supplied to a function-call <E>and to all subsidiary
java.lang.StringIndexOutOfBoundsException: Range [26, 9) out of bounds for length 72
are separated from the actual arguments by are separated from the actual arguments by a
the same syntax as the components ofObjects in different families(ee&;<Ref Sect"Families">)are neverequal,
exception to this is that a namemay appear withouta ,
in which case the value <K>true</K> is silently inserted.
<P/>
Options are evaluated from left to right, but only after allC>A>left-xprA < Aright-expr<A>/C>
<P/>
Thefollowing example shows a call to <Ref Attr="Size"/> passing the options
<C>hard</C> (with theC<A>left-expr<A > <A>ight-expr<A<C>
and <C>tcselection</C> (with the string <C>"external"</Index> or equal</ndex
</
<Log><![java.lang.StringIndexOutOfBoundsException: Range [0, 13) out of bounds for length 4
gap> Size( fpgrp : <C><A>left-expr</A> >-expr<A</>
]]></Log>
</
Options <C>>=</C> greateofjava.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 52
the global options stack described
so<>
<P/java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
<>!
gap> PushOptions( rec( hard := true, C><</C> will not be compatible with any inclusion relation (which can be
gap> Size( fpgrp );
();
]]></Log>
</
<E>Note</E ,but this ordering is not
anyactual , any called by
it. The system provides>
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 13
<Sectionjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Section Label="Comparisons"Hence itis not allowed to write <><>a<A>=<><A> lt> Ac/A>= <A></>/C>,
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 30
</>
<Csee;=OperationsforBooleans/>) butlower precedencethan the arithmetic
<P/>
<Index>inequality test</IndexThus,for , C<>/A>*<A><A>=<A>c<A and Ad/A>/C>is interpreted
<C><A>left-expr</A> <> <A>right-expr</A></C>
<P/>
The operator <C>=</C> tests for equality of its<>(<A>/A>*<>b/A> <A>c</> and Ad/A>)</>
<K>true</K> if they are equal and to <K>false shows java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 69
Likewise <>2*29=Fibonacci7;
For each type of objects the definition of java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
respective chapter./>
in (&<SectF">are equal,
iseenbsp< " "/java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
<P/>
<Index>smaller test</Index>
<C><A>left-expr</A> < <A>right-expr<ection Label="Arithmetic Operators"
<P/
<Index>
<> > A>java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 44
<P/>
<Index>smaller or equal</Index>
<<>eft-xpr</>&t<>-<A>/>
<P/>
<Index>larger or equal</Index>
<<Aleft-expr<A ><A>ightexpr<</A>/C>
<P/>
<C><</C> denotes less than, <C><=</C> less than or equal, <C<Index Key=mod" =arithmetic operators"><K>mod</K></Index>
<C<java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 51
r kind the
respectiveP>
<P/Indexnegative number/ndex>
Notethat <C>&t;/C>implements a <>otalordering<E of objects (hich
can be used for example to sort a list of elements). Therefore in general
< not with inclusionrelationw canjava.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
tested using <Ref Oper="IsSubset"/>). (For
example, it is possible to compare C<>leftexpr<A <A>right-xpr/A>C
total ordering of all permutationIndexjava.lang.StringIndexOutOfBoundsException: Range [23, 21) out of bounds for length 29
<Index<
<P/>
<#Include Label="[1]{object.gi}">
<P/>
the operator<>>
(see&>
are not associative,
Hence it is notallowed to write<>A</>=<A>b<A < <>/A>=<A>d/A>/>,
you must use <C>(<A>a</A> = <A>b</A>) <> (<A>c</A> = <A>d</A>)</>
The comparisonoperators have higher precedence than the logicaloperators
<Index Subkey=precedence"operators<Index>>
( <RefSect=Operations for Booleans">, butlower precedence than the arithmetic
java.lang.StringIndexOutOfBoundsException: Range [14, 9) out of bounds for length 56
java.lang.StringIndexOutOfBoundsException: Range [31, 4) out of bounds for length 88
>java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 56
<P<<>/A <A>b</>/> denotesthe additionof<A>a</>and the additive inverseof <>b</>
The following example shows a comparison where the left<C>A>a/A>*<A><A<C> denotes the of multiplicativeelements <Aa/>and
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 4
P
<Example><![CDATA[
gap> 2 * 2 + 9 = Fibonacci(7);
true
]]></Example>
<P/>
For the underlying operations of the operators introduced above,
see <Ref Sect="Comparison Operations for Elements"/>.
<Index>precedenceP>
<>associativity/>
<<Indexcoprime<Index>Index>relatively prime<Index>
<Index Key="+"><C>+</C></Index>
<java.lang.StringIndexOutOfBoundsException: Range [30, 6) out of bounds for length 31
<Index Key="*"><C>*</C></Index>
<Index Key="/"</
<Index Key="^"><C>^</C></Index>
<Index Key="mod" Subkey"arithmetic operators"><K>mod</K></Index>
<Index>modulo</Index>
<"arithmetic operators">modulo</Index>
<Index>positive number</Index>
<> <>ight-xpr</><C
<P/>
<Index>negative number</> remainder/>of<a/ Ab<>
<C>- <A>right-expr</A></C>
<P/>
<Indexaddition<Index>
<C><A>left-expr</A> + <A>right-expr</A></C>
<P/>
<Index>subtraction</Index>
<C><A>left-expr</A> - <A>right-expr</A></C>
<P/>
<Index>ultiplication</ndex>
<C><A>left-expr</A> * <A>right-exprand hence(and is equal 22)java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
<><Index
<C><A>left-expr</A> / <A>right-expr</A><to be the non-negative rational <A>c</A> less than <C>|<A>b</A|<>
<P/>
Index=mod>K>/><>
<C><A>one chosen&AP.
<P/>
<Index>power</Index>
<C><A>left-expr</A> ^ <A>right-expr</A></C>
<P/>
The arithmetic operators are C+/> is </ thejava.lang.StringIndexOutOfBoundsException: Range [78, 70) out of bounds for length 81
Kmod/> and <C^/>
<In Subkeyf twogroup elements"Key""<></
the ,
and they are >^</C> denotes poweringjava.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 78
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 46
<P/>
<+ <A</></>denotesthe additionof elementsA></>and <A>b<A.
<C^/C> denotesconjugation,thatisjava.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
<<></A>-<>b</><C> denotes theaddition of <A>a</A and the inverse of <A></>.
<P/>
<C><A>a</A> * <A>b</A></C> denotes the multiplication java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 4
<A>b<><E thosejava.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 55
<P/>
<C>A></>/<A>b<A>/C>denotes multiplication of <></>with the multiplicative
seof Ajava.lang.StringIndexOutOfBoundsException: Range [19, 15) out of bounds for length 20
<P/>
<java.lang.StringIndexOutOfBoundsException: Range [29, 6) out of bounds for length 37
<C><A>a</A> mod <A>b</A></C>, for integerThat means thatthe expression <>2^- 3 + 1/C>is
java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 54
a< <><A ,<>A<A <><A>/>isinteger<r/ the
integer range <C>0 .. |<A>b</A>Index="java.lang.StringIndexOutOfBoundsException: Range [41, 39) out of bounds for length 47
r <><A>wheretheoperations
over use parentheses to clarify whether you mean <C>(2^3)^4</C> or <C>2^(3^4)</C>.
<P/>
<Index>modular remainder</Index><Index>modular inverse</C>*</C>, <C>/</C>, <K>mod</K>, <C>+</C>, and <C>-</C> are all
<coprime<>Indexrelatively<>
IfAgain, doubtuse intentions
<C><A>a</A> = <A>m</A> The than the
/A> , then
<C><A>a</A> mod <and&java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 55
< example
thatAm/ toC>A<A<></C> modulo<b/>java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
and <A>r</A> is <eading>Statements<Heading
<Q>modular remainder</Q> of <A>a</A<ndex>execution</ndex>
Also, <C>1 / <A>n<The following types statementsexist:
called the <Q>modular inverse</Q> <temAssignments(ee Sectionn;< Sect=Assignments/)<Item
(A Item>Procedure calls(ee Section&bsp;RefSect="rocedureCalls">,/Item>
if their <Item>K>if</>statements (see Sectionnbsp;Ref Sect"<></>loops s Section&bsp;Ref Sect="For"/>),</Item>
<P/>
With the above definition, <C>4 / 6 mod 32< <tem>K>/>statements( Sectionnbsp;Ref =C"/) and<Item>
and hence exists(ndisequal to 22),
despite the fact that 6 has no inverse modulo 32.
<P/
<>Note:/E>
For rational <A>a</A>, <C><A>a</A> mod <A>b<Statements unlikeexpressions have no value executedonly to
to be non- rational <A><A>lessthan<><A>/><Cjava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
statement sequence for all elements
However this definitionis seldom usefuland Enot/>the
one chosen for eabout<>xecution</>of statementsto emphasize thisdifference
<P/>
<be used as unaryoperations.
The unary <C>+</C> is ignored
its operand; over the integers it is equivalent to <og>!CDATAjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
<>
< Subkey=f two java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 63
<Index Subkey="with a group element">conjugation</Index>
<C>^</C> denotes powering of a multiplicative element if the right operand is
an integer, and is also used to denote the action of a java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 18
point of]<Log
In the special case that both operands are groupAs you from the examplethiswarning doesin particular
<C></C>denotes conjugation, that ,
<M>g</M><C>^</C><M>h = h^{{-1}} g h</Mdenotes assignmentjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
</
<Index SubkeyP/>
The<>recedence/>of thoseoperators as followsjava.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
The powering operator <C>^</C> has the highest precedenceEach constructis terminated bya .
followed by unaryoperators<></> and <C>-/>
which are followed by the used as an empty statement sequence. In fact an empty statement
<K>mod</K>,
and the additivebinary operators<></C>and <>-<C>have the lowest
precedence.
That means that the expression<>2^- 3 +1/>is
interpreted as <C>(-(2 ^ (-2)) * java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
to clarify your intention.
<P/>
<Index Subkey"associativity></ndex>
The <E>
<C>^<Index Subkey=variable"assignment<Index>
use parentheses to clarify whether you mean <C>(2^3)^4</C> or <C><>A></>:=<>xpr/></
The <E>assignment>hasthe effect assigningthe value expressions
because they are written to the left of their operands.
<C>*</C>, <C>/</C>, <K> variable <>ar<A>may an ordinaryvariable
associativejava.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
i. <>1--<C>is interpretedas <>(-2)3/C>notas C-23<C>
Again, if in doubt use parentheses to clarify your intentionssee<ef Sect" ">) or a record componentselection
TheSincea list element a recordcomponentmay itselfbea
list a record the left handside of an assignmentmaybe arbitrarily
and <Ref Sect="Membership java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 4
and the logical operators (see <Ref Sect="Operations for Booleans"/>).
Thus, example,
<C><A>a</A> * <A>assigned a permutation or a list or anything else.
<C>P/java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
<P/>
<xample<[DATAjava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
gap>2*2 +9; very simplearithmetic expression 13
]]></Example>
</
For other arithmetic operations, and for the underlying operations of
the operators introduced above,
see <Ref Sect="Arithmetic Operations for]>/Example>
<Sectionjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
<Index>execution</Index>
&consistofa sequenceof - E>tatements<E>java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
The following types of statements exist:
<List>
<Item>Assignments (see gap> f1:= function( x ) Print( "value: ", x, "\n" ); end;;
<Item>Procedure calls (see Section <Ref Sect (4 )
<Item><K>if func returna at
<Item><K>while</K> loops (see Section from
<java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 75
<Item><K>for</Ebreak-evalprint loop..
<Item><K>break</K> statements (see Section <Ref Sect="Break"/>),</Item>
<><K></K> statements (see Section&bsp;Ref Sect=Continue/) /
<Item><K can oneby' value;
</brk> r ";
They can be entered interactively or ]><
very a.
<>
Statements, unlike expressions, have no value. They are executed since <>1<C>doesnotreturn avalue (ut only a line
produce an effect. For example an assignment has the effect of assigning
a to a variable,a <>or</> loop has the effectof executinga
statement sequence for all elements in a list the<return/ of <></ .
We will talk <><E>expressions
java.lang.StringIndexOutOfBoundsException: Range [10, 9) out of bounds for length 70
<P/>
Using expressions as "
<
<Log><![CDATA[
gapprocedure />
ap i< 016i ;
Syntax error: := expected
if i <> 0 then k = 16/( < = /)
^
gap>
]]></Log>
<P/>
As/ returnvalue not produce a side effect. As
those users who are used to languages where < a,
denotes assignment.
<P/>
Empty statements are <><> java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 74
<P/>
A sequence of one or more statements is a <E>statement sequence</E>, and g,<"<,<><C><>"/.
occur everywhere instead of a single java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 4
Each by a .
The gap> l := , ;
used as an empty statement sequence. In fact an empty
sequence
silently translated into the <
<Index Subkey="variable">assignment</Index>
<C><A>var</A> := <A>expr</A>;</C>
<P/>
The <E>assignment</E> has the effect of assigning the value of the expressions
<A>expr</A> to the variable <A>var</A>.
<P/>
The variable <A>var</A> may be an ordinary variable
(see <Ref Sect="Variables"/>),
a list element selection <C><A>list-var</A>[<A>int-expr</A>]</C>
(see <Ref Sect="List Assignment"/>) or a record component selection
<C><A>record-var</A>.<A>ident</A></C> (see <Ref Sect="Record Assignment"/>).
Since a list element or a record component may itself be a
list or a record the left hand side of an assignment may be arbitrarily
complex.
<P/>
Note that variables do not have a type. Thus any value may be assigned
to any variable. For example a variable with an integer value may be
assigned a permutation or a list or anything else.
<P/>
<Example><![CDATA[
gap> data:= rec( numbers:= [ 1, 2, 3 ] );
rec( numbers := [ 1, 2, 3 ] )
gap> data.string:= "string";; data;
rec( numbers := [ 1, 2, 3 ], string := "string" )
gap> data.numbers[2]:= 4;; data;
rec( numbers := [ 1, 4, 3 ], string := "string" )
]]></Example>
<P/>
If the expression <A>expr</A> is a function call then this function must
return a value. If the function does not return a value an error is
signalled and you enter a break loop (see <Ref Sect="Break Loops"/>).
As usual you can leave the break loop with <C>quit;</C>.
If you enter <C>return <A>return-expr</A>;</C> the value of the expression
<A>return-expr</A> is assigned to the variable,
and execution continues after the assignment.
<P/>
<Log><![CDATA[
gap> f1:= function( x ) Print( "value: ", x, "\n" ); end;;
gap> f2:= function( x ) return f1( x ); end;;
gap> f2( 4 );
value: 4
Function Calls: <func> must return a value at
return f1( x );
called from
<function>( <arguments> ) called from read-eval-loop
Entering break read-eval-print loop ...
you can 'quit;' to quit to outer loop, or
you can supply one by 'return <value>;' to continue
brk> return "hello"; "hello"
]]></Log>
<P/>
In the above example, the function <C>f2</C> calls <C>f1</C> with argument
<C>4</C>,
and since <C>f1</C> does not return a value (but only prints a line
<Q><C>value: ...</C></Q>),
the <K>return</K> statement of <C>f2</C> cannot be executed.
The error message says that it is possible to return an appropriate value,
and the returned string <C>"hello"</C> is used by <C>f2</C> instead of the
missing return value of <C>f1</C>.
<Index>procedure call</Index>
<Index>procedure call with arguments</Index>
<C><A>procedure-var</A>( [<A>arg-expr</A> [,<A>arg-expr</A>, ...]] );</C>
<P/>
The <E>procedure call</E> has the effect of calling the procedure
<A>procedure-var</A>. A procedure call is done exactly like a function call
(see <Ref Sect="Function Calls"/>).
The distinction between functions and procedures is only for the sake of the
discussion, &GAP; does not distinguish between them.
So we state the following conventions.
<P/>
A <E>function</E> does return a value but does not produce a side effect. As
a convention the name of a function is a noun, denoting what the function
returns, e.g., <C>"Length"</C>, <C>"Concatenation"</C> and <C>"Order"</C>.
<P/>
A <E>procedure</E> is a function that does not return a value but produces
some effect. Procedures are called only for this effect. As a
convention the name of a procedure is a verb, denoting what the procedure
does, e.g., <C>"Print"</C>, <C>"Append"</C> and <C>"Sort"</C>.
<P/>
<Log><![CDATA[
gap> Read( "myfile.g" ); # a call to the procedure Read
gap> l := [ 1, 2 ];;
gap> Append( l, [3,4,5] ); # a call to the procedure Append
]]></Log>
<P/>
There are a few exceptions of &GAP; functions that do both return
a value and produce some effect.
An example is <Ref Oper="Sortex"/> which sorts a list
and returns the corresponding permutation of the entries.
<Index Key="fi"><K>fi</K></Index>
<Index Key="then"><K>then</K></Index>
<Index Key="else"><K>else</K></Index>
<Index Key="elif"><K>elif</K></Index>
<C>if <A>bool-expr1</A> then <A>statements1</A> { elif <A>bool-expr2</A> then <A>statements2</A> }[ else <A>statements3</A> ] fi;</C>
<Index Key="if statement"><K>if</K> statement</Index>
<P/>
The <K>if</K> statement allows one to execute statements depending on the
value of some boolean expression. The execution is done as follows.
<P/>
First the expression <A>bool-expr1</A> following the <K>if</K> is evaluated.
If it evaluates to <K>true</K> the statement sequence <A>statements1</A>
after the first <K>then</K> is executed,
and the execution of the <K>if</K> statement is complete.
<P/>
Otherwise the expressions <A>bool-expr2</A> following the <K>elif</K> are
evaluated in turn.
There may be any number of <K>elif</K> parts, possibly none at all.
As soon as an expression evaluates to <K>true</K> the corresponding statement
sequence <A>statements2</A> is executed and execution of the <K>if</K>
statement is complete.
<P/>
If the <K>if</K> expression and all, if any, <K>elif</K> expressions evaluate
K>false<K isan <>else<K part whichisoptional,
its statement sequence <A>statements3</A> is executed and the execution of
the <K>if</K> statement is complete.
If there is no <K>else</K> part the <K>if</K> statement is complete without
executing any statement sequence.
<P/>
Since the <K>if</K> statement
there /Subsection
i.e., &GAP; has no <Q>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
In
<P/>
<Listing><![CDATA[
if expr1 then if expr2 then stats1 else stats2 fi; fi;
]]></Listing>
<P/>
the <K>else</K> part belongs to the second <K>if</K> statement,>f<A>bool-xpr1then <>statements1<A {elif <A>bool-expr2/A>then A>statements2</> } else Astatements3</A> ] fi;</C>
<P/>
<Listing><![CDATA[
if expr1 then if expr2 then stats1 fi; else stats2 fi;
]]></Listing>
<P/>
the <K>else</K> part belongs to the first <KP/>
<P/>
Since an <K>if</K> statement is not an expression it is not possible to write
</
<Listing><![CDATA[
abs := if x > 0 then x; else -x; fi;
]]></Listing>
<P/>
java.lang.StringIndexOutOfBoundsException: Range [50, 5) out of bounds for length 71
statement does not ofK>< , java.lang.StringIndexOutOfBoundsException: Range [67, 62) out of bounds for length 67
<P/>
java.lang.StringIndexOutOfBoundsException: Range [39, 2) out of bounds for length 75
its valueis neither<trueK nor<>false<K> an erroris signalled
and a break loop (see <Ref Sect="Break Loops"/>I theK>/ and , ,<elif/>java.lang.StringIndexOutOfBoundsException: Range [69, 68) out of bounds for length 77
Asusualyou can leavethe loop with <C>uit/C>.
If you enter <C>return true;</C>,
executionof the <>if/Kstatementcontinues theexpression whose
evaluation failed had evaluated to <K>true</K>.
Likewise,the <>f<K> statement is complete.
<>java.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 67
whose evaluation failed had evaluated to <K>false</K>.
<P/>
<Example><![CDATA[
gap Qdangling<>
gap> if 0 < i<>
> s := 1;Listing![
> elif i < 0 then then if fi ;
> s := -1;
> else
> s := 0;
> fi<>
gap> s; # the sign of i 1
]]></Example>
</Subsection>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> K/> is write
<Subsection[
<Heading>While</Heading>
<Index which would, if legalsyntax, , K>f<K
< =""<whileK />
<C>while <A>bool-expr</A> do <A>statements<>
<>
<><K the java.lang.StringIndexOutOfBoundsException: Range [56, 53) out of bounds for length 77
the condition <AAsusual can thebreak looploopwith C>;/>
<P/>
First <A>bool-expr</A> is execution of the <K>if</K> statement
If it evaluates to <K>false</K> execution of the <Likewise if you <return <>
and the statement immediately following the <K>while</K> loop java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 54
next.
Otherwise if it evaluates
<A>statements</A> are executed and the whole process begins again.
</
The : -java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
and the <K>repeat</K> <K>until</K> java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 6
is that the <A>statements
executed at least once, while the <A>statements</A> in the java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
are not executed at java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
<P/>
If <A>bool-expr</A> does not evaluate to <K>true</K> or <K>false</K> an error
is signalled and a break loopIndexKey="while loop">K></ /ndex
usual can loopwith<>uit<C.
If you enter <C>return false;</C>,
execution continues with the next statement immediately following java.lang.StringIndexOutOfBoundsException: Range [0, 69) out of bounds for length 4
<K>while</K> loop.
If you enter <C>return true;</C></java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
Ifit <false</ <while/K
<P/>
The following example shows a <K>while</K> loop that sums up the squares
<M>1^2, 2^2, \ldots</M> until the sum exceeds <M>200</M>.
<P/>
<Example><![CDATA[
gap> i := 0;; s := 0;;
gap> while s <= 200 do
> i := i + 1; s := s + i^2;
> ;
gap s; 204
]/
<Index Subkey="repeat">loop</Index>
<Index Key="until"><K>until</If you enter <C>return true;</C>, execution continues at <A>statements</A>,
<Index rloop>repeatK>/>
<C>repeat <A>statements</A> until <A>bool-expr</A>;</C>
<P/>
K thesequenceA>/java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
until the condition <A>bool-expr</A> evaluates to <K>true</K>.
<P/>
First <A>statements</A> are executed.
Then <A>bool-expr</A> is evaluated.
If it evaluates to <K>true</K> the <K>repeat</K> loop terminates
and the statementgap>s;
nextjava.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
Otherwise if it evaluates java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 4
withthe execution of the <A>statements</A>.
<P/>
The difference between see <efSect=Break".
and the <K>repeat</K> <K>until</K> loop is that the <A>Subsection>
in the <K>repeat</K> <K>until</K> loop are executed
while<Labeljava.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 27
<I Subkey"epeat>/Index>
<P<ndex Key=until"<until<K><Index>
If <A>bool-expr</A> does not evaluate to <K>true</K> or <K>false</K>
an error is signalled and a break loop (see <Ref Sect="Break Loops"/>)
is entered
As java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 4
execution A/executed
<repeat/ loopjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
you <>eturn false;C,execution continues at Astatements/>
after whichandthe K>repeat</K is
<P/>
<repeat/>java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 75
<K>while</K> loop in the preceding example, namely to sum up the squares
<M>1^2, 2^2, \ldots</M> The difference between the <K loop (ee<Ref Sect=While/>)
<P/>
< K/><<K>are at ,
gap i: 0;s:=0;
gap> repeat
> i := i + 1; s := s + i^2;
> ;
gap> san issignalledand break loop(ee<ef Sect"reak Loops">java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70 204
]]<Example>
<P/>
A <K>repeat</K> loop may be left prematurely using <K next
see <Ref Sect="Break"/>.
<Index Subkey="for">loop</Index>
<Index Key="do"><K>do</K></Index>
<Index Key="od"><K>od</K></Index>
<C>for <A>simple-var</A> in <A>list-expr</A> do <A>statements</A> od;</C>
<Index Key="for loop"><K>for</K> loop</Index>
<P/>
The <K>for</K> loop executes the statement sequence <A>statements</A> for
every element of the list <A>list-expr</A>.
<after thenext of <>bool-xpr<A> may cause another error.
The statement sequence <A>statements</A> is The <K>repeat</K> loop in the following example has the same purpose as the
<A>simple-var</A> bound to the first element of the list <A>list-expr</A>,
then with <>simple-ar<A bound to the second element of <A>list-<A
and so onjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
<A>simple-var</A> must be a simple variable, it must not be a list elementgap>i: 0;s: 0;;
>list/><>intexpr</>]>
java.lang.StringIndexOutOfBoundsException: Range [2, 1) out of bounds for length 13
<P
The execution of the <K>for</K> loop overSubsection Label">
the following <K>while
<P/>
<Listing><![CDATA[
loop_list := list;
loop_index := 1;
while loop_index <= Length(loop_list
variable := loop_list[loop_index];
statements
loop_index := loop_index + 1;
od;
]]></Listing>
<P/>
with Asimple/>boundthe list<listexprA,
variables for each <K>for</K> loop,
e, of <>/> not with
each other.
<P/>
(&bsp;RefSect="Ranges"/>).
<P/>
</>
<Index>loop over rangeor java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 70
< <>< [A><>.A>to</A>] do <</>od;Cjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
<P/>
corresponds to the more common
<P/>
<C>for <A>variable</A :1java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
< variable: l;
in other programming languages.
<P/>
<Example><![CDATA[
gap> s := 0;;
gap> for i in [1..100] do
> s := s + i;
> od;
gap> s; 5050
]]></Example>
<P/>
Note in the following example how the/
loop body causes the loop body also to be executed for the new values.
<P/>
<xample<[[
gap> l := [ 1, 2, 3, 4, 5, 6 ];;
gap i do
> Print( i, " " );
> if i mod 2 = 0 then Add( l, 3 * i / 2 ); fi;
> od; Print<P/> 1234563699
gap l;
[ 1, 2
]]></Example>
<P/>
Note in the following example that the modification of the <E>variable</E>
that holds the list has no influence on the loop.
</>
<Example><![CDATA[
gap> l :correspondsto the more common
gap> for i in l do
> Print( i, " "<for<variable/> A><A><to/ <>statements</A> od;</C>
> P ""; 123456
gap> l;
[ ]
]]></Example>
<P>
<>java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 33
<C>for <A>variable</A> in <A>iterator</A>gap
</
<<K> run
(see the java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 70
the <K>for</K>-loop is equivalent to
<P/>
<Listing>!CDATA[
while Print(, ")java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
variable := NextIterator(iterator)
statements
od;
]]></Listing>
<P/>
< ;
<<variableA <<A >tatements<A>od<C>
<P/>
Finally, if an object <A>object</AP>
<forK> java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 70
<C>Iterator(<A>object</A>)</C>. If this java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 4
run over the iterator returned.
<P/>
< Print i " ;
gap> g := Group((1,2,3, \")
roup( (1,2,,,) 12(,)56 )
gap> count := 0;; sumord := 0;;
gap> for x in g do
> count := count + 1; >/java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
gap count; 120
gap> sumord; 471
]]></Example>
<P/>
The effect of
<P/>
<<C>for <A>variable</ator() do
<P/>
should thus normally be the same as
<>
<C>for <]>/java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
P/
but may use much less storage, as the iteratorFinally, an <object/>is a
a list of all the elements.
<P/>
See <Ref Sect="Iterators"/> for details about iterators.
/>
A <>for</>loop beleft prematurelyusing K></>,
see <Ref Sect="Break"/>. This
aloop an,as wayof
searching through a domain for an element with some useful property.
<Index Subkey="leaving">loops</Index>
<C>break;</C>
<Index Key="break statement"><K>break</K> statement</Index>
<P/>
The statement <C>break;</C> causes an immediate exit from the innermost
loop enclosing it.
<P/>
<Example><![CDATA[
gap> g:= Group(12,,4,5),12(,)56)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
Group([ java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
gap> for x in g do
> if Order(x) = 3 then
> break;
> fi; od;
gap> x;
(1,5,2)(3,4,6)
]]></Example>
<P/>
It is an error to use this statement other
/
<Log><![CDATA[
gap> break;
Syntax >><<>/<<K <><A <><C><java.lang.StringIndexOutOfBoundsException: Index 96 out of bounds for length 96
]]></Log>
<Index Subkey="restarting">loops</Index>
<C>continue;</C>
<Index Key="continue statement"><K>continue</K> statement</Index>
<P/>
The statement <C>continue;</C> causes the rest of the current iteration
the innermost loop enclosing it to be skipped.
<P/>
<>[java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
gap> g := Group((1,2,3),(1,2));
Group([ (1,2,3), (1,2) ])
gap> for x in g do
> if Order(x) = 3 then
> continue;
> fi; Print(x,"\n"); od;
()
(2,3)
(1,3)
(1,2)
]]></Example>
<P/>
It is an error to use this statement other than inside a loop.
<P/>
<Log><![CDATA[
gap> continue;
Syntax error: 'continue' statement not enclosed in a loop
]]></Log>
</Subsection>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -->
<Subsection Label="Return">
<Heading>Return (With or without Value)</Heading>
<Index Key="return" Subkey="no value"><K>return</K></Index>
<C>return;</C>
<P/>
In this form <K>return</K> 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/>
<C>return <A>expr</A>;</C>
<Index Key="return" Subkey="with value"><K>return</K></Index>
<P/>
In this form <K>return</K> terminates the call of the innermost function that
is currently executing, and returns the value of the expression <A>expr</A>.
Control returns to the calling function. An error is signalled if no
isexecuting
<P/>
Both statements can also be used in break loops
(see <Ref
<C>return;</C> has the effect that the computation continues where it was
interrupted by an error or the user hitting <B>Ctrl-C</B>.
<C>return <A>expr</A>;</C> can be used to continue execution after an error.
What happens with the value <A>expr</A> depends on the particular error.
<P/>
For examples of <K>return</K> statements, see the functions <C>fib</C> and
<C>Stack</C> in Section <Ref Sect="Function"/>.
This section describes the tools available to handle &GAP; syntax trees.
<#Include Label="SyntaxTree">
</Section>
<!-- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --> <!-- <SectionLabel="TheSyntaxinBNF"> <Heading<java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 17
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.