syntax.xml
No OneTemporary

File Metadata

Created
Fri, Mar 13, 9:05 PM

syntax.xml

<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.1" xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:trans="http://docbook.org/ns/transclusion"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/ns/docbook">
<?xxe-sn 26yv439af40 59?>
<title><?xxe-sn 26yv439af40 5a?>Syntax</title>
<para><?xxe-sn 26yv439af40 5b?><informaltable>
<?xxe-sn 26yv439af40 5c?>
<tgroup cols="3">
<?xxe-sn 26yv439af40 5d?>
<tbody>
<?xxe-sn 26yv439af40 5e?>
<row>
<?xxe-sn 26yv439af40 5f?>
<entry><?xxe-sn 26yv439af40 5g?>Literals, Expressions, Basic
Statements</entry>
<entry><?xxe-sn 26yv439af40 5h?>Annotations</entry>
<entry><?xxe-sn 26yv439af40 5i?>Intrinsics: query</entry>
</row>
<row>
<?xxe-sn 26yv439af40 5j?>
<entry><?xxe-sn 26yv439af40 5k?>Identifiers, Code Blocks</entry>
<entry><?xxe-sn 26yv439af40 5l?>Branch Statements</entry>
<entry><?xxe-sn 26yv439af40 5m?>Interfaces: Extern-C</entry>
</row>
<row>
<?xxe-sn 26yv439af40 5n?>
<entry><?xxe-sn 26yv439af40 5o?>Functions</entry>
<entry><?xxe-sn 26yv439af40 5p?>Loops</entry>
<entry><?xxe-sn 26yv439af40 5q?>Other: Transcend, Versions</entry>
</row>
<row>
<?xxe-sn 26yv439af40 5r?>
<entry><?xxe-sn 26yv439af40 5s?>Types</entry>
<entry><?xxe-sn 26yv439af40 5t?>Variants</entry>
<entry><?xxe-sn 26yv439af40 5u?></entry>
</row>
</tbody>
</tgroup>
</informaltable></para>
<para><?xxe-sn 26yv439af40 5v?>There are number of principles Xreate syntax
based on:</para>
<itemizedlist>
<?xxe-sn 26yv439af40 5w?>
<listitem>
<?xxe-sn 26yv439af40 5x?>
<para><?xxe-sn 26yv439af40 5y?>Follows SSA form: each identifier is
defined only once and no redefinitions allowed</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 5z?>
<para><?xxe-sn 26yv439af40 60?>Order in which identifiers are defined
does not influence computation order. Identifiers are computed in order
based on dependencies between expressions. Order in which identifiers
are defines reflects personal preferences and what is convenient for a
developer.</para>
</listitem>
</itemizedlist>
<section>
<?xxe-sn 26yv439af40 61?>
<title><?xxe-sn 26yv439af40 62?>Literals and expressions</title>
<para><?xxe-sn 26yv439af40 63?>Xreate expressions have a form:</para>
<synopsis><?xxe-sn 26yv439af40 64?>SYNTAX:
//expression// [:: //type//; //annotations-list// ]</synopsis>
<itemizedlist>
<?xxe-sn 26yv439af40 fd?>
<listitem>
<?xxe-sn 26yv439af40 fe?>
<para><?xxe-sn 26yv439af40 ff?><emphasis><?xxe-sn 26yv439af40 fg?>annotation-list</emphasis>
is a list of annotations delimited by semicolon.</para>
</listitem>
</itemizedlist>
<para><?xxe-sn 26yv439af40 67?>Expressions consist of literals and various
operations as follows:</para>
<informaltable>
<?xxe-sn 26yv439af40 68?>
<tgroup cols="2">
<?xxe-sn 26yv439af40 69?>
<colspec colwidth="115*"><?xxe-sn 26yv439af40 6a?></colspec>
<colspec colwidth="885*"><?xxe-sn 26yv439af40 6b?></colspec>
<tbody>
<?xxe-sn 26yv439af40 6c?>
<row>
<?xxe-sn 26yv439af40 6d?>
<entry><?xxe-sn 26yv439af40 6e?>Literals</entry>
<entry><?xxe-sn 26yv439af40 6f?>numbers, strings: <code><?xxe-sn 26yv439af40 6g?>5,
"Nimefurahi kukujua"</code></entry>
</row>
<row>
<?xxe-sn 26yv439af40 6h?>
<entry><?xxe-sn 26yv439af40 6i?>Lists, records</entry>
<entry><?xxe-sn 26yv439af40 6j?>Record is a collection of elements
of different types — <code><?xxe-sn 26yv439af40 6k?>{year = 1934,
month = "april"}</code>. List is a collection of elements of the
same type without keys — <code><?xxe-sn 26yv439af40 6l?>{16, 8,
3}</code>. Range of elements — <code><?xxe-sn 2apiasqubk0 4?>[1..18]</code>.</entry>
</row>
<row>
<?xxe-sn 26yv439af40 6m?>
<entry><?xxe-sn 26yv439af40 6n?>Arithmetic operations</entry>
<entry><?xxe-sn 26yv439af40 6o?>Basic arithmetic operations:
<code><?xxe-sn 26yv439af40 6p?>+, -, *, /</code></entry>
</row>
<row>
<?xxe-sn 26yv439af40 6q?>
<entry><?xxe-sn 26yv439af40 6r?>Relations</entry>
<entry><?xxe-sn 26yv439af40 6s?><code><?xxe-sn 26yv439af40 6t?>==,
!=, &lt;&gt;, &lt;, &lt;=, &gt;, &gt;=</code>. Both
<code><?xxe-sn 26yv439af40 6u?>!=, &lt;&gt;</code> mean
<emphasis><?xxe-sn 26yv439af40 6v?>not equal</emphasis> relation.
Examples: <code><?xxe-sn 26yv439af40 6w?>8&gt;=3, "Blue" &lt;&gt;
"Green"</code></entry>
</row>
<row>
<?xxe-sn 26yv439af40 6x?>
<entry><?xxe-sn 26yv439af40 6y?>List and struct operations</entry>
<entry><?xxe-sn 26yv439af40 6z?><emphasis><?xxe-sn 26yv439af40 70?>index</emphasis>
operation to access individual elements of a list or a record.
Example: <code><?xxe-sn 26yv439af40 71?>colors = {"Green",
"Blue"}::[string]. color = colors[0]:: string.</code> Record's
element access: <code><?xxe-sn 26yv439af40 72?>date = {year =
1934, month = "april"}. year = date["year"]</code></entry>
</row>
<row>
<?xxe-sn 26yv439af40 73?>
<entry><?xxe-sn 26yv439af40 74?>Identifiers</entry>
<entry><?xxe-sn 26yv439af40 75?>Example: <code><?xxe-sn 26yv439af40 76?>a
- b</code></entry>
</row>
<row>
<?xxe-sn 26yv439af40 77?>
<entry><?xxe-sn 26yv439af40 78?>Functions</entry>
<entry><?xxe-sn 26yv439af40 79?>Example: <code><?xxe-sn 26yv439af40 7a?>result
= isOdd(6).</code></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</section>
<section>
<?xxe-sn 26yv439af40 7b?>
<title><?xxe-sn 26yv439af40 7c?>Code Blocks</title>
<para><?xxe-sn 26yv439af40 7d?>Block is a list of expressions delimited by
period. It has a <emphasis><?xxe-sn 26yv439af40 7e?>body</emphasis> - main
expression and optionally some identifier definitions.</para>
<synopsis><?xxe-sn 26yv439af40 7f?>SYNTAX:
{
[//ident// = //expression// . | //body-expression// . ]..
}</synopsis>
<para><?xxe-sn 26yv439af40 7g?>Code block consists of <emphasis><?xxe-sn 26yv439af40 7h?>body
expression</emphasis> and optional set of assignments to define
identifiers used in body expression. Block's computation is defined as a
result of associated body expression's computation. Identifiers are
computed before expressions they are used in.</para>
<programlisting xml:id="CodeBlocks1"><?xxe-sn 26yv439af40 7i?>name="tests/ast.cpp: AST.Doc_CodeBlocks1"
test = function:: int
{
a = 10:: int.
b = 2:: int.
a + b:: int
}</programlisting>
<para><?xxe-sn 26yv439af40 7j?>Above is an example of code block which
have <code><?xxe-sn 26yv439af40 7k?>a+b</code> as a body expression. In
this case body depends on identifiers <code><?xxe-sn 26yv439af40 7l?>a</code>,
<code><?xxe-sn 26yv439af40 7m?>b</code> so compiler computes both of them
beforehand.</para>
<para><?xxe-sn 26yv439af40 7n?>Computation order depends only on
dependencies between expressions. This approach has properties as
follows:</para>
<itemizedlist>
<?xxe-sn 26yv439af40 7o?>
<listitem>
<?xxe-sn 26yv439af40 7p?>
<para><?xxe-sn 26yv439af40 7q?>Mutually independent identifiers can be
evaluated in any order</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 7r?>
<para><?xxe-sn 26yv439af40 7s?>Identifier gets computed only if it's
required(even transitively) by block's body expression.</para>
</listitem>
</itemizedlist>
</section>
<section>
<?xxe-sn 26yv439af40 7t?>
<title><?xxe-sn 26yv439af40 7u?>Functions</title>
<synopsis><?xxe-sn 26yv439af40 7v?>SYNTAX:
//function-name// = **function** ([//argument//:: //type//[; //annotation-list//]]...):: //return-type// [; //annotations//]...
//function-block//</synopsis>
<itemizedlist>
<?xxe-sn 26yv439af40 7w?>
<listitem>
<?xxe-sn 26yv439af40 7x?>
<para><?xxe-sn 26yv439af40 7y?><emphasis><?xxe-sn 26yv439af40 7z?>function-name</emphasis>
name of function</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 80?>
<para><?xxe-sn 26yv439af40 81?><emphasis><?xxe-sn 26yv439af40 82?>argument</emphasis>
formal parameter. Arguments are delimited by comma.</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 83?>
<para><?xxe-sn 26yv439af40 84?><emphasis><?xxe-sn 26yv439af40 85?>type</emphasis>,
<emphasis><?xxe-sn 26yv439af40 86?>return-type</emphasis> formal
parameter and returning value types</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 87?>
<para><?xxe-sn 26yv439af40 88?><emphasis><?xxe-sn 26yv439af40 89?>function-block</emphasis>
code block that acts as a function's definition</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 8a?>
<para><?xxe-sn 26yv439af40 8b?><emphasis><?xxe-sn 26yv439af40 8c?>annotations</emphasis>
list of annotations delimited by semicolon</para>
</listitem>
</itemizedlist>
<para><?xxe-sn 26yv439af40 8d?>Below is an example of a function
<code><?xxe-sn 26yv439af40 8e?>sum</code>. It takes two arguments and
returns their sum. Also it defines several annotations. First annotation
<code><?xxe-sn 26yv439af40 8f?>entry</code> has a special meaning — it
depicts entry point or main function in a program. Second annotation
<code><?xxe-sn 26yv439af40 8g?>status(needs_review)</code> is a
demonstration that developers can annotate function using custom
annotations to express different properties.</para>
<programlisting xml:id="Functions1"><?xxe-sn 26yv439af40 8h?>name="tests/ast.cpp: AST.Doc_Functions1"
sum = function(x:: int, y:: int):: int; entry; status(needs_review)
{
x+y
}</programlisting>
</section>
<section>
<?xxe-sn 26yv439af40 8i?>
<title><?xxe-sn 26yv439af40 8j?>Function Specializations</title>
<synopsis><?xxe-sn 26yv439af40 8k?>SYNTAX:
**guard**:: //annotation//
{
//functions-list//
}</synopsis>
<itemizedlist>
<?xxe-sn 26yv439af40 8l?>
<listitem>
<?xxe-sn 26yv439af40 8m?>
<para><?xxe-sn 26yv439af40 8n?><emphasis><?xxe-sn 26yv439af40 8o?>annotation</emphasis>
Guard expressed by annotation</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 8p?>
<para><?xxe-sn 26yv439af40 8q?><emphasis><?xxe-sn 26yv439af40 8r?>functions-list</emphasis>
one or more function that share the same guard</para>
</listitem>
</itemizedlist>
<para><?xxe-sn 26yv439af40 8s?>Xreate allows several functions to share
the same name. In which case they are called <emphasis><?xxe-sn 26yv439af40 fk?>
specializations</emphasis>. This is syntactic foundation for
<emphasis><?xxe-sn 26yv439af40 8u?>function level polymorphism</emphasis>,
i.e. ability for compiler to decide which exactly function is called out
of several options. Polymorphism resolution can happen during compilation
or at run-time.</para>
<para><?xxe-sn 26yv439af40 8v?>Functions with the same name, i.e.
different specializations should have additional unique identifiers called
<emphasis><?xxe-sn 26yv439af40 8w?>guards</emphasis>. When function is
actually called it's expected that resolution is already done at some
point before and supplies correct guard to uniquely specify which exactly
specialization to call.</para>
<para><?xxe-sn 26yv439af40 8x?>Example:</para>
<programlisting xml:id="FunctionSpecialization1"><?xxe-sn 26yv439af40 8y?>name="tests/ast.cpp: AST.Doc_FunctionSpecializations1"
guard:: safe_enviroment
{
sum = function (a::int, b::int) :: int
{
a + b
}
}</programlisting>
<note>
<?xxe-sn 26yv439af40 8z?>
<para><?xxe-sn 26yv439af40 90?>See <link
xlink:href="/d/transcend/ast-api/#function-s-specializatio"><?xxe-sn 26yv439af40 91?>API</link>
to get more information on how guards are processed</para>
</note>
</section>
<section>
<?xxe-sn 26yv439af40 92?>
<title><?xxe-sn 26yv439af40 93?>Branch Statements</title>
<section>
<?xxe-sn 26yv439af40 94?>
<title><?xxe-sn 26yv439af40 95?>IF Statement</title>
<synopsis><?xxe-sn 26yv439af40 96?>SYNTAX:
**if** (//condition//):: //type// [; //annotations// ]..
//block-true//
**else**
//block-false//</synopsis>
<para><?xxe-sn 26yv439af40 97?><code><?xxe-sn 26yv439af40 fh?>IF</code>
statement executes <emphasis><?xxe-sn 26yv439af40 98?>block-true</emphasis>
or <emphasis><?xxe-sn 26yv439af40 99?>block-false</emphasis> depending
on <emphasis><?xxe-sn 26yv439af40 9a?>condition</emphasis> evaluation
result.</para>
<para><?xxe-sn 26yv439af40 9b?>Example:</para>
<programlisting xml:id="IfStatement1"><?xxe-sn 26yv439af40 9c?>name="tests/ast.cpp: AST.Doc_BranchStatements"
answer = if (question == "Favorite color?"):: string
{"Yellow"} else {"Don't know"}.</programlisting>
</section>
<section>
<?xxe-sn 26yv439af40 9d?>
<title><?xxe-sn 26yv439af40 9e?>SWITCH Statement</title>
<synopsis><?xxe-sn 26yv439af40 9f?>SYNTAX:
**switch** ( //condition// ) :: //type// [; //annotations//]..
[**case** ( //guard// ) code-block]..
**case default** //default-code-block//
</synopsis>
<itemizedlist>
<?xxe-sn 26yv439af40 9g?>
<listitem>
<?xxe-sn 26yv439af40 9h?>
<para><?xxe-sn 26yv439af40 9i?><emphasis><?xxe-sn 26yv439af40 9j?>condition</emphasis>'s
result is used to decide which branch to execute next</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 9k?>
<para><?xxe-sn 26yv439af40 9l?><emphasis><?xxe-sn 26yv439af40 9m?>guard</emphasis>
value to match against <emphasis><?xxe-sn 26yv439af40 9n?>condition</emphasis></para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 9o?>
<para><?xxe-sn 26yv439af40 9p?><emphasis><?xxe-sn 26yv439af40 9q?>default-code-block</emphasis>
executed if no appropriate case found</para>
</listitem>
</itemizedlist>
<para><?xxe-sn 26yv439af40 9r?>SWITCH statement evaluation's result is
that of branch whose <emphasis><?xxe-sn 26yv439af40 9s?>guard</emphasis>
matches <emphasis><?xxe-sn 26yv439af40 9t?>condition</emphasis>.</para>
<para><?xxe-sn 26yv439af40 9u?>Example:</para>
<programlisting xml:id="SwitchStatement1"><?xxe-sn 26yv439af40 9v?>name="tests/ast.cpp: AST.Doc_BranchStatements"
monthName = switch(monthNum) :: string
case (1) {"Jan"}
case (2) {"Feb"}
case default {"Strange.. Don't know this month"}.</programlisting>
</section>
</section>
<section>
<?xxe-sn 26yv439af40 9w?>
<title><?xxe-sn 26yv439af40 9x?>Loop Statements</title>
<section>
<?xxe-sn 26yv439af40 9y?>
<title><?xxe-sn 26yv439af40 9z?>LOOP Statement</title>
<synopsis><?xxe-sn 26yv439af40 a0?>SYNTAX:
**loop** ( //init-value// -&gt; //accumulator// ):: //type// [; //annotations//] //loop-body//</synopsis>
<itemizedlist>
<?xxe-sn 26yv439af40 a1?>
<listitem>
<?xxe-sn 26yv439af40 a2?>
<para><?xxe-sn 26yv439af40 a3?><emphasis><?xxe-sn 26yv439af40 a4?>init-value</emphasis>
initial value loop starts from</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 a5?>
<para><?xxe-sn 26yv439af40 a6?><emphasis><?xxe-sn 26yv439af40 a7?>accumulator</emphasis>
identifier which holds loop's result after each iteration</para>
</listitem>
</itemizedlist>
<para><?xxe-sn 26yv439af40 a8?>For each iteration <emphasis><?xxe-sn 26yv439af40 a9?>accumulator</emphasis>
assumes result of previous iteration or <emphasis><?xxe-sn 26yv439af40 aa?>init-value</emphasis>
during first iteration. Result of the <emphasis><?xxe-sn 26yv439af40 ab?>loop-body</emphasis>
evaluation is used as <emphasis><?xxe-sn 26yv439af40 ac?>accumulator</emphasis>'s
next iteration value and as overall loop statement result after the last
iteration.</para>
<para><?xxe-sn 26yv439af40 ad?>This notation does not have termination
condition. Compiler relies on loop body's fixed point in order to decide
when to interrupt loop. Let's consider example:</para>
<programlisting xml:id="LoopStatement1"><?xxe-sn 26yv439af40 ae?>COUNTEREXAMPLE, name="tests/ast.cpp: AST.Doc_LoopStatements"
//infinite loop
answer = loop (2-&gt;x) :: int
{
if(IsPerfect(x)):: int {x} else {x+1}
}.</programlisting>
<para><?xxe-sn 26yv439af40 af?>The example tests numbers for being
perfect(sum of all proper divisors equals to the number itself). While
iterating accumulator <code><?xxe-sn 26yv439af40 ag?>x</code> assumes
values as follows: 2, 3, 4, 5, 6, 6 ... After it founds first perfect
number any further iteration do not change result anymore since there is
no increment and it continues to test the same number again and again.
Obviously, <code><?xxe-sn 26yv439af40 ah?>x=6</code> is a fixed point in
this example. There is no point to continue going through further
iterations once fixed point is evaluated and hence loop can be safely
interrupted.</para>
<para><?xxe-sn 26yv439af40 ai?>Compiler relies on manually provided
annotations to recognize when fixed point is reached. There is special
annotation <code><?xxe-sn 26yv439af40 aj?>final</code> to specify fixed
point for loops. Once expression marked as <code><?xxe-sn 26yv439af40 ak?>final</code>
gets evaluated it's assumed to be a fixed point or in other words
compiler knows it's the very last iteration after which loop ends.
Correct code for the example above is:</para>
<programlisting xml:id="LoopStatement2"><?xxe-sn 26yv439af40 al?>name="tests/ast.cpp: AST.Doc_LoopStatements"
//loop exits after first perfect number is found
answer2 = loop (2-&gt;x) :: int
{
if(IsPerfect(x))::int {x:: int; final} else {x+1}
}.</programlisting>
<para><?xxe-sn 26yv439af40 am?>In this case compiler able to recognize
when fixed point is reached to exit loop. After loops is done
<code><?xxe-sn 26yv439af40 an?>answer</code> is <code><?xxe-sn 26yv439af40 ao?>6</code>.</para>
</section>
<section>
<?xxe-sn 26yv439af40 ap?>
<title><?xxe-sn 26yv439af40 aq?>LOOP FOLD Statement</title>
<synopsis><?xxe-sn 26yv439af40 ar?>SYNTAX:
**loop fold** (//list// **-&gt;** //element//:: //type// [; //annotations//], //init-value// **-&gt;** //accumulator//):: //type// [; //annotations//]
//loop-body//</synopsis>
<itemizedlist>
<?xxe-sn 26yv439af40 as?>
<listitem>
<?xxe-sn 26yv439af40 at?>
<para><?xxe-sn 26yv439af40 au?><emphasis><?xxe-sn 26yv439af40 av?>list</emphasis>
to iterate through</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 aw?>
<para><?xxe-sn 26yv439af40 ax?><emphasis><?xxe-sn 26yv439af40 ay?>element</emphasis>
identifier that assumes value of currently processed list
element</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 az?>
<para><?xxe-sn 26yv439af40 b0?><emphasis><?xxe-sn 26yv439af40 b1?>type</emphasis>,
<emphasis><?xxe-sn 26yv439af40 b2?>annotations</emphasis> expression
types and optional annotations delimited by semicolon</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 b3?>
<para><?xxe-sn 26yv439af40 b4?><emphasis><?xxe-sn 26yv439af40 b5?>init-value</emphasis>
accumulator's initial value loop starts with</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 b6?>
<para><?xxe-sn 26yv439af40 b7?><emphasis><?xxe-sn 26yv439af40 b8?>accumulator</emphasis>
identifier assumes loop-body evaluation result after each
iteration</para>
</listitem>
</itemizedlist>
<para><?xxe-sn 26yv439af40 b9?>Iterates over <emphasis><?xxe-sn 26yv439af40 ba?>list</emphasis>
in order to accumulate result by applying <emphasis><?xxe-sn 26yv439af40 bb?>loop-body</emphasis>
transformation to each <emphasis><?xxe-sn 26yv439af40 bc?>element</emphasis>
and intermediate <emphasis><?xxe-sn 26yv439af40 bd?>accumulator</emphasis>.
Overall loop value is a accumulator's value after the last iteration. If
fixed point is found an execution terminates earlier.</para>
<para><?xxe-sn 26yv439af40 be?>Example shows code excerpt that looks for
a minimal element in the given list(and less then initial value
<code><?xxe-sn 26yv439af40 bf?>10</code>).</para>
<programlisting xml:id="FoldStatement1"><?xxe-sn 26yv439af40 bg?>name="tests/ast.cpp: AST.Doc_LoopStatements"
numbers = {4, 8, 7, 1, 5}:: [int].
min = loop fold(numbers-&gt;x:: int, 10-&gt;acc):: int
{
if (acc &gt; x):: int {x} else {acc}
}.</programlisting>
</section>
<section>
<?xxe-sn 26yv439af40 bh?>
<title><?xxe-sn 26yv439af40 bi?>LOOP MAP Statement</title>
<synopsis><?xxe-sn 26yv439af40 bj?>SYNTAX:
**loop map** (//list// **-&gt;** //element// :: //type// [; //annotations// ] ) :: //type// [; //annotations// ]
//loop-body//</synopsis>
<itemizedlist>
<?xxe-sn 26yv439af40 bk?>
<listitem>
<?xxe-sn 26yv439af40 bl?>
<para><?xxe-sn 26yv439af40 bm?><emphasis><?xxe-sn 26yv439af40 bn?>list</emphasis>
to iterate through</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 bo?>
<para><?xxe-sn 26yv439af40 bp?><emphasis><?xxe-sn 26yv439af40 bq?>element</emphasis>
identifier that assumes value of currently processed list
element</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 br?>
<para><?xxe-sn 26yv439af40 bs?><emphasis><?xxe-sn 26yv439af40 bt?>type</emphasis>,
<emphasis><?xxe-sn 26yv439af40 bu?>annotations</emphasis> type and
optional annotations delimited by semicolon.</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 bv?>
<para><?xxe-sn 26yv439af40 bw?><emphasis><?xxe-sn 26yv439af40 bx?>loop-body</emphasis></para>
</listitem>
</itemizedlist>
<para><?xxe-sn 26yv439af40 by?>Iterates over input <emphasis><?xxe-sn 26yv439af40 bz?>list</emphasis>
and applies <emphasis><?xxe-sn 26yv439af40 c0?>loop-body</emphasis>
transformation to each element. Result is a list that consists of all
transformed elements.</para>
<programlisting xml:id="MapStatement1"><?xxe-sn 26yv439af40 c1?>name="tests/ast.cpp: AST.Doc_LoopStatements"
odd_numbers = {1, 3, 5}:: [int].
even_numbers = loop map(odd_numbers-&gt;number::int) :: [int]
{ 2 * number }.</programlisting>
<para><?xxe-sn 26yv439af40 c2?>Example demonstrates creating
<code><?xxe-sn 26yv439af40 c3?>even_number</code> list by multiplying by
2 every element of <code><?xxe-sn 26yv439af40 c4?>odd_numbers</code>.</para>
</section>
</section>
<section>
<?xxe-sn 26yv439af40 c5?>
<title><?xxe-sn 26yv439af40 c6?>Types</title>
<para><?xxe-sn 26yv439af40 c7?>Primitive Types</para>
<informaltable>
<?xxe-sn 26yv439af40 c8?>
<tgroup cols="2">
<?xxe-sn 26yv439af40 c9?>
<colspec colwidth="173*"><?xxe-sn 26yv439af40 ca?></colspec>
<colspec colwidth="827*"><?xxe-sn 26yv439af40 cb?></colspec>
<tbody>
<?xxe-sn 26yv439af40 cc?>
<row>
<?xxe-sn 26yv439af40 cd?>
<entry><?xxe-sn 26yv439af40 ce?><code><?xxe-sn 26yv439af40 cf?>num</code></entry>
<entry><?xxe-sn 26yv439af40 cg?><code><?xxe-sn 26yv439af40 ch?>i32</code>
alias. Reserved as a placeholder for auto detected appropriate
either integral of floating-point type</entry>
</row>
<row>
<?xxe-sn 26yv439af40 ci?>
<entry><?xxe-sn 26yv439af40 cj?><code><?xxe-sn 26yv439af40 ck?>int</code></entry>
<entry><?xxe-sn 26yv439af40 cl?><code><?xxe-sn 26yv439af40 cm?>i32</code>
alias. Reserved as a placeholder for auto detected appropriate
integral type</entry>
</row>
<row>
<?xxe-sn 26yv439af40 cn?>
<entry><?xxe-sn 26yv439af40 co?><code><?xxe-sn 26yv439af40 cp?>float</code></entry>
<entry><?xxe-sn 26yv439af40 cq?>Double precision floating-point
number</entry>
</row>
<row>
<?xxe-sn 26yv439af40 cr?>
<entry><?xxe-sn 26yv439af40 cs?><code><?xxe-sn 26yv439af40 ct?>bool</code></entry>
<entry><?xxe-sn 26yv439af40 cu?>Boolean type</entry>
</row>
<row>
<?xxe-sn 26yv439af40 cv?>
<entry><?xxe-sn 26yv439af40 cw?><code><?xxe-sn 26yv439af40 cx?>i8,
i32, i64</code></entry>
<entry><?xxe-sn 26yv439af40 cy?>Signed integers. 8, 32, 64 bit
wide respectively</entry>
</row>
<row>
<?xxe-sn 26yv439af40 cz?>
<entry><?xxe-sn 26yv439af40 d0?><code><?xxe-sn 26yv439af40 d1?>string</code></entry>
<entry><?xxe-sn 26yv439af40 d2?>Pointer to a null terminated ANSI
char string. Reserved for auto detected most appropriate string
type.</entry>
</row>
<row>
<?xxe-sn 26yv439af40 d3?>
<entry><?xxe-sn 26yv439af40 d4?><code><?xxe-sn 26yv439af40 d5?>*</code></entry>
<entry><?xxe-sn 26yv439af40 d6?>Unspecified type. Example
<code><?xxe-sn 26yv439af40 d7?>x = {amount=200,
currency="USD"}::*.</code></entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para><?xxe-sn 26yv439af40 d8?>Compound types:</para>
<informaltable>
<?xxe-sn 26yv439af40 d9?>
<tgroup cols="2">
<?xxe-sn 26yv439af40 da?>
<colspec colwidth="312*"><?xxe-sn 26yv439af40 db?></colspec>
<colspec colwidth="688*"><?xxe-sn 26yv439af40 dc?></colspec>
<tbody>
<?xxe-sn 26yv439af40 dd?>
<row>
<?xxe-sn 26yv439af40 de?>
<entry><?xxe-sn 26yv439af40 df?><code><?xxe-sn 26yv439af40 dg?>[
<emphasis><?xxe-sn 26yv439af40 dh?>element-type</emphasis>
]</code></entry>
<entry><?xxe-sn 26yv439af40 di?>List of elements of the same type
<emphasis><?xxe-sn 26yv439af40 dj?>element-type</emphasis>.
Example: <code><?xxe-sn 26yv439af40 dk?>[int]</code> - list of
<code><?xxe-sn 26yv439af40 dl?>int</code>'s</entry>
</row>
<row>
<?xxe-sn 26yv439af40 dm?>
<entry><?xxe-sn 26yv439af40 dn?><code><?xxe-sn 26yv439af40 do?>{<emphasis><?xxe-sn 26yv439af40 dp?>key</emphasis>::
<emphasis><?xxe-sn 26yv439af40 dq?>type</emphasis>,
...}</code></entry>
<entry><?xxe-sn 26yv439af40 dr?>List of elements of different type
possibly with named keys. Examples: <code><?xxe-sn 26yv439af40 ds?>{int,
string}</code>, <code><?xxe-sn 26yv439af40 dt?>{name::string,
age::int}</code></entry>
</row>
<row>
<?xxe-sn 26yv439af40 du?>
<entry><?xxe-sn 26yv439af40 dv?><code><?xxe-sn 26yv439af40 dw?>variant
{<emphasis><?xxe-sn 26yv439af40 dx?>option</emphasis> ::
(<emphasis><?xxe-sn 26yv439af40 dy?>type</emphasis>, ...},
...}</code></entry>
<entry><?xxe-sn 26yv439af40 dz?>Holds a single element of type of
one out of number of options. Examples: <code><?xxe-sn 26yv439af40 e0?>variant
{FullAddress:: {string, string, string}, ShortAddress::
{string}}</code></entry>
</row>
<row>
<?xxe-sn 26yv439af40 e1?>
<entry><?xxe-sn 26yv439af40 e2?><code><?xxe-sn 26yv439af40 e3?>slave
<emphasis><?xxe-sn 26yv439af40 e4?>identifier</emphasis></code></entry>
<entry><?xxe-sn 26yv439af40 e5?>Type determined by Transcend.
Example: <code><?xxe-sn 26yv439af40 e6?>slave
unit_test</code></entry>
</row>
<row>
<?xxe-sn 26yv439af40 e7?>
<entry><?xxe-sn 26yv439af40 e8?><code><?xxe-sn 26yv439af40 e9?><emphasis><?xxe-sn 26yv439af40 ea?>compound-type</emphasis>
[ <emphasis><?xxe-sn 26yv439af40 eb?>key</emphasis>
]</code></entry>
<entry><?xxe-sn 26yv439af40 ec?>Accessing elements of compound
type. Example: <code><?xxe-sn 26yv439af40 ed?>Bio = type
{birth_year:: int, name:: string}. Year = type
Bio[birth_year].</code></entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para><?xxe-sn 26yv439af40 ee?>New types defined as:</para>
<synopsis><?xxe-sn 26yv439af40 ef?>SYNTAX:
//type-name// = **type** (//parameters//...) //type-definition// .</synopsis>
<para><?xxe-sn 26yv439af40 eg?>Example:</para>
<programlisting xml:id="Types1"><?xxe-sn 26yv439af40 eh?>name="tests/ast.cpp: AST.Doc_Types"
Tuple = type {string, int}.
Int = type Tuple[1]. //accessing by index</programlisting>
</section>
<section>
<?xxe-sn 26yv439af40 ei?>
<title><?xxe-sn 26yv439af40 ej?>Variants and SWITCH VARIANT
Instruction</title>
<synopsis><?xxe-sn 26yv439af40 ek?>SYNTAX:
**switch variant** ( //condition// [-&gt; //alias// ] [:: //type// [; //annotations//... ] ] ) :: type [; annotations... ]
[ **case** ( //guard// ) //case-branch// ]...</synopsis>
<itemizedlist>
<?xxe-sn 26yv439af40 el?>
<listitem>
<?xxe-sn 26yv439af40 em?>
<para><?xxe-sn 26yv439af40 en?><emphasis><?xxe-sn 26yv439af40 eo?>condition</emphasis>
expression of variant type</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 ep?>
<para><?xxe-sn 26yv439af40 eq?><emphasis><?xxe-sn 26yv439af40 er?>alias</emphasis>
identifier to denote unwrapped content of condition withing case
branches.</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 es?>
<para><?xxe-sn 26yv439af40 et?><emphasis><?xxe-sn 26yv439af40 eu?>guard</emphasis>
name of variant to match against actual condition's variant</para>
</listitem>
<listitem>
<?xxe-sn 26yv439af40 ev?>
<para><?xxe-sn 26yv439af40 ew?><emphasis><?xxe-sn 26yv439af40 ex?>case-branch</emphasis>
block of code to execute in case of matched variant. Content is
accessible by using alias Within the branch .</para>
</listitem>
</itemizedlist>
<para><?xxe-sn 26yv439af40 ey?>Sometimes it is useful for a variable to
have value of different types depending on some conditions, in other words
it has <emphasis><?xxe-sn 26yv439af40 ez?>variant type</emphasis>.</para>
<para><?xxe-sn 26yv439af40 f0?>Let's consider example with variable
<code><?xxe-sn 26yv439af40 fi?>month</code> of variant type
<code><?xxe-sn 26yv439af40 fj?>Month</code>:</para>
<programlisting xml:id="Variants1"><?xxe-sn 26yv439af40 f3?>name="tests/ast.cpp: AST.Doc_Variants"
Month = type variant {
MonName :: {string},
MonNumber:: {int}
}.
test = function:: Month
{
month = MonName("April"):: Month.
month
}</programlisting>
<para><?xxe-sn 26yv439af40 f4?>Variable <code><?xxe-sn 26yv439af40 f5?>month</code>
holds value of either <code><?xxe-sn 26yv439af40 f6?>string</code> or
<code><?xxe-sn 26yv439af40 f7?>int</code> type. Value is not accessible
directly. It should be <emphasis><?xxe-sn 26yv439af40 f8?>unwrapped</emphasis>
before using. Xreate supports <code><?xxe-sn 26yv439af40 f9?>switch variant</code>
instruction for this operation.</para>
<para><?xxe-sn 26yv439af40 fa?>As an example below is function
<code><?xxe-sn 26yv439af40 fb?>nextMonth</code>'s definition:</para>
<programlisting><?xxe-sn 26yv439af40 fc?>nextMonth = function(month:: Month):: Month
{
switch variant(month):: Month
case (MonName)
{
//
}
case (MonNumber)
}</programlisting>
</section>
</chapter>
<?xxe-revisions
#3 2019-02-23T12:37:01Z pgess
#2 2018-12-18T15:50:51Z pgess
1sPEAAABgeMqAFCB4lUAASggLXObCwEBE4EIIx9DFRMsY4GNb0MjQyITB1MEY4FhcyNTBBMFIzdD
tF4Amw6BCYEpmU2BCIGXHoGOHowjjkUmXYgkgatoghiCZA==
#1 2018-12-18T15:11:23Z pgess
1sPEAAABgeJVADCB4lkAABkQc+xgE5kzQ5JQgwhTshozg19DkFhTCmODEwDsX5kyEZJXshmDXoYP
ilQ=
?>

Event Timeline