<?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 5v?>There is a number of principles the Xreate
  syntax is based on:</para>

  <itemizedlist>
    <?xxe-sn 26yv439af40 5w?>

    <listitem>
      <?xxe-sn 26yv439af40 5x?>

      <para><?xxe-sn 26yv439af40 5y?>Follows SSA(single assignment) form: each
      identifier is defined only once and no redefinitions allowed.</para>
    </listitem>

    <listitem>
      <?xxe-sn 26yv439af40 5z?>

      <para><?xxe-sn 26yv439af40 60?>Follows literate programming principles
      where possible. For example, identifiers can be defined in any order
      reflecting personal preferences and convenience for a developer.
      Regardless of the definition order, expressions are computed based on
      dependencies between them. Literate programming principles from a
      practical point of view simplify code testing, support, catching
      regressions, etc.</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 2ese8ot7ke8 e?>5</code>,
            <code><?xxe-sn 2ese8ot7ke8 f?>"Nimefurahi kukujua"</code>.</entry>
          </row>

          <row>
            <?xxe-sn 26yv439af40 6h?>

            <entry><?xxe-sn 26yv439af40 6i?>Lists, records</entry>

            <entry><?xxe-sn 26yv439af40 6j?><emphasis><?xxe-sn 2ese8ot7ke8 c?>Record</emphasis>
            is a collection of elements of different types - <code><?xxe-sn 26yv439af40 6k?>{year = 1934, month = "april"}</code>.
            <emphasis><?xxe-sn 2ese8ot7ke8 d?>List</emphasis> is a collection
            of elements of the same type without keys - <code><?xxe-sn 26yv439af40 6l?>{16, 8, 3}</code>.
            Range is a specific form of a list - <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 2ese8ot7ke8 g?>+</code>, <code><?xxe-sn 2ese8ot7ke8 h?>-</code>,
            <code><?xxe-sn 2ese8ot7ke8 i?>*</code>, <code><?xxe-sn 2ese8ot7ke8 j?>/</code>.</entry>
          </row>

          <row>
            <?xxe-sn 2evpzktyvg7 -wunr7fl0rw8j?>

            <entry><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8i?>Boolean
            operations</entry>

            <entry><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8h?>Negation example:
            <code><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8g?>-isEmty()</code>.</entry>
          </row>

          <row>
            <?xxe-sn 26yv439af40 6q?>

            <entry><?xxe-sn 26yv439af40 6r?>Relations</entry>

            <entry><?xxe-sn 26yv439af40 6s?><code><?xxe-sn 2ese8ot7ke8 r?>==</code>,
            <code><?xxe-sn 2ese8ot7ke8 s?>!=</code>, <code><?xxe-sn 2ese8ot7ke8 t?>&lt;&gt;</code>,
            <code><?xxe-sn 2ese8ot7ke8 u?>&lt;</code>, <code><?xxe-sn 2ese8ot7ke8 v?>&lt;=</code>,
            <code><?xxe-sn 2ese8ot7ke8 w?>&gt;</code>, <code><?xxe-sn 2ese8ot7ke8 x?>&gt;=</code>.
            Both <code><?xxe-sn 2ese8ot7ke8 y?>!=</code>, <code><?xxe-sn 2ese8ot7ke8 z?>&lt;&gt;</code>
            mean <emphasis><?xxe-sn 26yv439af40 6v?>not equal</emphasis>
            relation. Examples: <code><?xxe-sn 2ese8ot7ke8 10?>8&gt;=3</code>,
            <code><?xxe-sn 2ese8ot7ke8 11?>"Blue" &lt;&gt; "Green"</code>.</entry>
          </row>

          <row>
            <?xxe-sn 26yv439af40 6x?>

            <entry><?xxe-sn 26yv439af40 6y?>List and record operations</entry>

            <entry><?xxe-sn 26yv439af40 6z?>The <emphasis><?xxe-sn 26yv439af40 70?>index</emphasis>
            operation to access individual elements of a list or record.
            Example: <code><?xxe-sn 2ese8ot7ke8 12?>colors = {"Green", "Blue"}::[string]. color = colors[0]:: string.</code>
            Accesing a record's element: <code><?xxe-sn 2ese8ot7ke8 13?>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):: bool.</code></entry>
          </row>
        </tbody>
      </tgroup>
    </informaltable>
  </section>

  <section>
    <?xxe-sn 2evpzktyvg7 -wunr7fl0rw8v?>

    <title><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8u?>Annotations</title>

    <para><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8t?>This chapter is about Brute
    syntax. See <link xlink:href="/d/transcend/"><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8l?>Transcend</link>
    for details regarding Transcend and annotations syntax.</para>
  </section>

  <section>
    <?xxe-sn 26yv439af40 7b?>

    <title><?xxe-sn 26yv439af40 7c?>Code Blocks</title>

    <para><?xxe-sn 26yv439af40 7d?>Code block is a list of expressions
    delimited by a period. It has a <emphasis><?xxe-sn 26yv439af40 7e?>body</emphasis>
    - the main expression along with optional identifiers' definitions.</para>

    <synopsis><?xxe-sn 26yv439af40 7f?>SYNTAX:
{
  [//ident// = //expression//. | //body-expression//. ]..
}</synopsis>

    <para><?xxe-sn 26yv439af40 7g?>Code blocks consist of <emphasis><?xxe-sn 26yv439af40 7h?>a
    body expression</emphasis> and an optional set of assignments to define
    identifiers used in the body expression. A code block's computation result
    is defined as a result of computing its body expression. Identifiers are
    computed before expressions they are appear in, regardless of a
    definitions' order.</para>

    <programlisting xml:id="CodeBlocks1"><?xxe-sn 26yv439af40 7i?>name="tests/ast.cpp: AST.Doc_CodeBlocks1"
test = function:: int; entry
{
  a + b::   int

  a = 10::  int. 
  b = 2::   int.
}</programlisting>

    <para><?xxe-sn 26yv439af40 7j?>Above is an example of the code block with
    <code><?xxe-sn 26yv439af40 7k?>a+b</code> as its body expression(because
    it does not have a form of an assignment). In this case the body depends
    on the identifiers <code><?xxe-sn 26yv439af40 7l?>a</code>,
    <code><?xxe-sn 26yv439af40 7m?>b</code> so the compiler computes both of
    them beforehand.</para>

    <para><?xxe-sn 26yv439af40 7n?>A 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?>An identifier computed only if it is
        required(at least transitively) by a code 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 a function.</para>
      </listitem>

      <listitem>
        <?xxe-sn 26yv439af40 80?>

        <para><?xxe-sn 26yv439af40 81?><emphasis><?xxe-sn 26yv439af40 82?>argument</emphasis>
        Formal parameters. 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's and returning value's 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 the function
    <code><?xxe-sn 26yv439af40 8e?>sum</code> returning sum of its two
    arguments. Moreover there are several annotations defined. First
    annotation <code><?xxe-sn 26yv439af40 8f?>entry</code> has a special
    meaning — it depicts an entry point or a main function in a program.
    Second annotation <code><?xxe-sn 26yv439af40 8g?>status(needs_review)</code>
    is a demonstration that developers can annotate functions using custom
    annotations to express related intentions or 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 in the form of an annotation.</para>
      </listitem>

      <listitem>
        <?xxe-sn 26yv439af40 8p?>

        <para><?xxe-sn 26yv439af40 8q?><emphasis><?xxe-sn 26yv439af40 8r?>functions-list</emphasis>
        One or more functions that share the same guard.</para>
      </listitem>
    </itemizedlist>

    <para><?xxe-sn 26yv439af40 8s?>Specializations is a crucial Xreate concept
    serving as the principal connection between Transcend and Brute levels.
    Xreate allows several functions to share the same name; in this case they
    are called <emphasis><?xxe-sn 26yv439af40 fk?> specializations</emphasis>.
    This is a syntactic foundation for <emphasis><?xxe-sn 26yv439af40 8u?>function
    level <link xlink:href="/d/concepts/polymorphism/"><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8k?>polymorphism</link></emphasis>,
    i.e. ability for the compiler to decide which exactly function is called
    out of several available options. The polymorphism resolution can happen
    during compilation(early polymorphism) or at run-time(late
    polymorphism).</para>

    <para><?xxe-sn 26yv439af40 8v?>Functions with the same name, i.e.
    different specializations must have identifiers called <emphasis><?xxe-sn 26yv439af40 8w?>guards</emphasis>
    to uniquely define a specialization. In this sense, a shared name is just
    a placeholder, which only along with a guard comprise the fully qualified
    exact function identifier. On the Brute level it is possible to specify
    only a function's shared name for invocation. On the other hand, Transcend
    is responsible to supply a guard part. When a function is actually called
    by its name in a program it's expected that the resolution is already done
    by Transcend at some time earlier and it supplies the correct guard to
    uniquely specify which exactly specialization to call. This gives
    Transcend a deep control over an actual program behaviour.</para>

    <para><?xxe-sn 26yv439af40 8x?>An example:</para>

    <programlisting xml:id="FunctionSpecialization1"><?xxe-sn 26yv439af40 8y?>name="tests/ast.cpp: AST.Doc_FunctionSpecializations1", lines=15
guard::                              safe_enviroment 
{
  sum = function (a::int, b::int)::  int 
  {
    result = a + b::                 int.

    if (-isLastOpOverflow(result)):: int
    {
      result
    } 
      else 
    {
      overflowErrorCode()
    }
  }
}

guard::                              fast_enviroment 
{
  sum = function (a::int, b::int) :: int 
  {
    a + b
  }
}</programlisting>

    <para><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8f?>To alter existing code behaviour
    it's always possible to add new specializations and adjust Transcend rules
    to specify situations when a new specialization should(or should not) be
    used.</para>

    <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 detailed information on how guards are processed on the
      Transcend side.</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?>The <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 the <emphasis><?xxe-sn 26yv439af40 9a?>condition</emphasis>
      evaluation's 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>
          Expression to 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?>The <code><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8e?>switch</code>
      statement evaluation's result is that of the branch whose
      <emphasis><?xxe-sn 26yv439af40 9s?>guard</emphasis> matches the
      <emphasis><?xxe-sn 26yv439af40 9t?>condition</emphasis>.</para>

      <para><?xxe-sn 26yv439af40 9u?>An 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 {"It's strange..an unexpected month"}.</programlisting>
    </section>
  </section>

  <section>
    <?xxe-sn 26yv439af40 9w?>

    <title><?xxe-sn 26yv439af40 9x?>Loops</title>

    <para><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8d?>Xreate loops are constructed in
    such a way that they hide actually mutable operations semantic under an
    immutable facade compatible with a single assignment form.</para>

    <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 a 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 the result of a previous iteration or <emphasis><?xxe-sn 26yv439af40 aa?>init-value</emphasis>
      for the first iteration. The result of <emphasis><?xxe-sn 26yv439af40 ab?>loop-body</emphasis>
      evaluation is used as a <emphasis><?xxe-sn 26yv439af40 ac?>accumulator</emphasis>'s
      next iteration value and as an overall loop statement result after the
      last iteration.</para>

      <para><?xxe-sn 26yv439af40 ad?>Note, that this notation does not have an
      explicit termination condition! The compiler relies on the loop body's
      fixed point in order to decide when to interrupt the loop. Consider an
      example:</para>

      <programlisting xml:id="LoopStatement1"><?xxe-sn 26yv439af40 ae?>COUNTEREXAMPLE, name="tests/ast.cpp: AST.Doc_LoopStatements"
//an 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). During
      iterations the accumulator <code><?xxe-sn 26yv439af40 ag?>x</code>
      assumes values as follows: 2, 3, 4, 5, 6, 6... After the first perfect
      number is found, no further iteration will change the result anymore
      since there is no increment, so the loop continues to go through the
      same number again and again, making this an infinite loop. Obviously,
      <code><?xxe-sn 26yv439af40 ah?>x=6</code>(the first perfect number) is a
      fixed point in this example. It does not make any sense to continue
      going through further iterations once a fixed point is reached because
      the result is not going to be changed anymore, thus the loop can be
      safely interrupted at this point.</para>

      <para><?xxe-sn 26yv439af40 ai?>The compiler relies on manually provided
      annotations to recognize when a fixed point is reached. There is a
      special annotation <code><?xxe-sn 26yv439af40 aj?>final</code> reserved
      to specify a fixed point for loops. Once an expression that marked as
      <code><?xxe-sn 26yv439af40 ak?>final</code> gets evaluated it's assumed
      that a fixed point is reached or in words the compiler knows it's the
      very last iteration after which loop can be terminated safely. The
      correct code for the example above is:</para>

      <programlisting xml:id="LoopStatement2"><?xxe-sn 26yv439af40 al?>name="tests/ast.cpp: AST.Doc_LoopStatements"
//a loop exits after the 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 the compiler is able to
      recognize that a fixed point is reached in order to know when it is safe
      to terminate the loop. In the example, the final result <code><?xxe-sn 26yv439af40 an?>answer2</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>
          Container to iterate over.</para>
        </listitem>

        <listitem>
          <?xxe-sn 26yv439af40 aw?>

          <para><?xxe-sn 26yv439af40 ax?><emphasis><?xxe-sn 26yv439af40 ay?>element</emphasis>
          Identifier that assumes value of a currently processing 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 from.</para>
        </listitem>

        <listitem>
          <?xxe-sn 26yv439af40 b6?>

          <para><?xxe-sn 26yv439af40 b7?><emphasis><?xxe-sn 26yv439af40 b8?>accumulator</emphasis>
          Identifier that assumes loop-body evaluation result after each
          iteration.</para>
        </listitem>
      </itemizedlist>

      <para><?xxe-sn 26yv439af40 b9?>The <code><?xxe-sn 2evpzktyvg7 -wunr7fl0rw87?>loop fold</code>
      statement is a commonly used particular instance of <code><?xxe-sn 2evpzktyvg7 -wunr7fl0rw85?>loop</code>
      to Iterate over <emphasis><?xxe-sn 26yv439af40 ba?>list</emphasis> in
      order to accumulate the result by applying the <emphasis><?xxe-sn 26yv439af40 bb?>loop-body</emphasis>
      transformation to each <emphasis><?xxe-sn 26yv439af40 bc?>element</emphasis>
      and an intermediate <emphasis><?xxe-sn 26yv439af40 bd?>accumulator</emphasis>.
      The result of a current iteration is used as the <emphasis><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8b?>accumulator</emphasis>
      value for a next iteration. Accordingly, the overall loop value equals
      that of <emphasis><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8c?>accumulator</emphasis>
      after the last iteration. If a fixed point is found evaluation
      terminates earlier.</para>

      <para><?xxe-sn 26yv439af40 be?>Example shows a code excerpt that looks
      for the minimal element in a given list(and less then the 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>
          Container to iterate over.</para>
        </listitem>

        <listitem>
          <?xxe-sn 26yv439af40 bo?>

          <para><?xxe-sn 26yv439af40 bp?><emphasis><?xxe-sn 26yv439af40 bq?>element</emphasis>
          Identifier that assumes value of a 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>
      </itemizedlist>

      <para><?xxe-sn 26yv439af40 by?>The <code><?xxe-sn 2evpzktyvg7 -wunr7fl0rw84?>loop fold</code>
      statement is a commonly used particular instance of <code><?xxe-sn 2evpzktyvg7 -wunr7fl0rw83?>loop</code>
      to Iterate over <emphasis><?xxe-sn 26yv439af40 bz?>list</emphasis> and
      applying the <emphasis><?xxe-sn 26yv439af40 c0?>loop-body</emphasis>
      transformation to each element. The result is a list that consists of
      all the transformed elements.</para>

      <para><?xxe-sn 2evpzktyvg7 -wunr7fl0rw8a?>An example below demonstrates
      creating the <code><?xxe-sn 2evpzktyvg7 -wunr7fl0rw89?>even_number</code>
      list by multiplying by 2 every element of <code><?xxe-sn 2evpzktyvg7 -wunr7fl0rw88?>odd_numbers</code>:</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>
    </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 2ey6qxf8um8 1?>

            <entry><?xxe-sn 2ey6qxf8um8 2?><code><?xxe-sn 2ey6qxf8um8 7?>bool</code></entry>

            <entry><?xxe-sn 2ey6qxf8um8 8?>Booleans.</entry>
          </row>

          <row>
            <?xxe-sn 2ey6qxf8um8 3?>

            <entry><?xxe-sn 2ey6qxf8um8 4?><code><?xxe-sn 2ey6qxf8um8 9?>i8</code>,
            <code><?xxe-sn 2ey6qxf8um8 a?>i32</code>, <code><?xxe-sn 2ey6qxf8um8 b?>i64</code></entry>

            <entry><?xxe-sn 2ey6qxf8um8 c?>Signed integers; 8, 32, 64 bit wide
            respectively.</entry>
          </row>

          <row>
            <?xxe-sn 2ey6qxf8um8 5?>

            <entry><?xxe-sn 2ey6qxf8um8 6?><code><?xxe-sn 2ey6qxf8um8 f?>int</code>,
            <code><?xxe-sn 2ey6qxf8um8 g?>num</code></entry>

            <entry><?xxe-sn 2ey6qxf8um8 d?>Currently <code><?xxe-sn 2ey6qxf8um8 e?>i32</code>
            aliases. Reserved as placeholders for an auto detected appropriate
            integral type and for auto detected appropriate either integral of
            floating-point type, respectively.</entry>
          </row>

          <row>
            <?xxe-sn 26yv439af40 ci?>

            <entry><?xxe-sn 26yv439af40 cj?><code><?xxe-sn 26yv439af40 ck?>float</code></entry>

            <entry><?xxe-sn 26yv439af40 cl?>Double precision floating-point
            numbers.</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?>Currently null terminated ANSI
            char string. Reserved to be generic type with no particular
            implementation. A concrete implementation is to be determined
            similarly to the <link
            xlink:href="/d/concepts/containers/"><?xxe-sn 2ey6qxf8um8 h?>containers</link>
            approach.</entry>
          </row>

          <row>
            <?xxe-sn 26yv439af40 d3?>

            <entry><?xxe-sn 26yv439af40 d4?><code><?xxe-sn 26yv439af40 d5?>*</code></entry>

            <entry><?xxe-sn 26yv439af40 d6?>An unspecified type. Postpones
            type checks for this expression. Examples: <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?>[ <emphasis><?xxe-sn 2ey6qxf8um8 j?>element-type</emphasis> ]</entry>

            <entry><?xxe-sn 26yv439af40 di?>List of elements of the same type
            <emphasis><?xxe-sn 26yv439af40 dj?>element-type</emphasis>.
            Examples: <code><?xxe-sn 26yv439af40 dk?>x = {1, 2, 3}:: [int]</code>
            - list of <code><?xxe-sn 26yv439af40 dl?>int</code>'s. Lists can
            have different internal implementations.</entry>
          </row>

          <row>
            <?xxe-sn 26yv439af40 dm?>

            <entry><?xxe-sn 26yv439af40 dn?>{<emphasis><?xxe-sn 2ey6qxf8um8 k?> key</emphasis>:: <emphasis><?xxe-sn 2ey6qxf8um8 l?>type</emphasis>, ... }</entry>

            <entry><?xxe-sn 26yv439af40 dr?>Record: a list of elements of
            different types possibly with named keys. Examples:
            <code><?xxe-sn 2ey6qxf8um8 15?>{int, string}</code>,
            <code><?xxe-sn 2ey6qxf8um8 16?>{name::string, age::int}</code>.</entry>
          </row>

          <row>
            <?xxe-sn 26yv439af40 du?>

            <entry><?xxe-sn 26yv439af40 dv?>variant {<emphasis><?xxe-sn 2ey6qxf8um8 m?>option</emphasis> :: {<emphasis><?xxe-sn 2ey6qxf8um8 n?>type</emphasis>, ...}, ...}</entry>

            <entry><?xxe-sn 26yv439af40 dz?>ADT type. Variables of this type
            can hold value of any type out of a list of permitted ones.
            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?>slave <emphasis><?xxe-sn 2ey6qxf8um8 o?>identifier</emphasis></entry>

            <entry><?xxe-sn 26yv439af40 e5?>Denotes a type constructed by
            Transcend. See <link xlink:href="#slave-types"><?xxe-sn 2ezs03nkiyo 17?>slave
            types</link>. An example: <code><?xxe-sn 26yv439af40 e6?>slave unit_test</code>.</entry>
          </row>
        </tbody>
      </tgroup>
    </informaltable>

    <para><?xxe-sn 2ey6qxf8um8 p?>Type operations:</para>

    <informaltable>
      <?xxe-sn 2ey6qxf8um8 q?>

      <tgroup cols="2">
        <?xxe-sn 2ey6qxf8um8 r?>

        <colspec colwidth="115*"><?xxe-sn 2ey6qxf8um8 17?></colspec>

        <colspec colwidth="885*"><?xxe-sn 2ey6qxf8um8 18?></colspec>

        <tbody>
          <?xxe-sn 2ey6qxf8um8 s?>

          <row>
            <?xxe-sn 2ey6qxf8um8 t?>

            <entry><?xxe-sn 2ey6qxf8um8 u?><emphasis><?xxe-sn 2ey6qxf8um8 v?>type</emphasis> [ <emphasis><?xxe-sn 2ey6qxf8um8 w?>key</emphasis> ]</entry>

            <entry><?xxe-sn 2ey6qxf8um8 x?>Index operation: accessing elements
            of a compound type. Examples: <code><?xxe-sn 2ey6qxf8um8 y?>Bio = type {birth_year:: int, name:: string}. YearBirth = type Bio[birth_year].</code></entry>
          </row>

          <row>
            <?xxe-sn 2ey6qxf8um8 z?>

            <entry><?xxe-sn 2ey6qxf8um8 10?><emphasis><?xxe-sn 2ey6qxf8um8 12?>type</emphasis> ( <emphasis><?xxe-sn 2ey6qxf8um8 13?>parameters</emphasis>... )</entry>

            <entry><?xxe-sn 2ey6qxf8um8 11?>Constructs a concrete type with
            the given parameters. Examples: <code><?xxe-sn 2ey6qxf8um8 14?>MyTree = type Tree(int)</code>.</entry>
          </row>
        </tbody>
      </tgroup>
    </informaltable>

    <para><?xxe-sn 26yv439af40 ee?>New types are defined as follows:</para>

    <synopsis><?xxe-sn 26yv439af40 ef?>SYNTAX:
//type-name// = **type** (//parameters//...) //type-definition// .</synopsis>

    <para><?xxe-sn 26yv439af40 eg?>Examples:</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

List = type(X) [X]. // List of elements of type X.
IntList = type List(int). // type function to construct List of ints.</programlisting>

    <section>
      <?xxe-sn 2f0cduzin5j -wunr7fl0rw8v?>

      <title><?xxe-sn 2f0cduzin5j -wunr7fl0rw8u?>Slave Types</title>

      <synopsis><?xxe-sn 2f0cduzin5j -wunr7fl0rw8t?>SYNTAX:
**slave** //predicate//
</synopsis>

      <itemizedlist>
        <?xxe-sn 2f0cduzin5j -wunr7fl0rw8s?>

        <listitem>
          <?xxe-sn 2f0cduzin5j -wunr7fl0rw8r?>

          <para><?xxe-sn 2f0cduzin5j -wunr7fl0rw8q?><emphasis><?xxe-sn 2f0cduzin5j -wunr7fl0rw8p?>predicate</emphasis>
          Name of a logic predicate</para>
        </listitem>
      </itemizedlist>

      <para><?xxe-sn 2f0cduzin5j -wunr7fl0rw8o?>Slave type is a reference to a
      type defined on the Transcend side. This gives Transcend a full control
      over program types marked as <code><?xxe-sn 2f0cduzin5j -wunr7fl0rw8n?>slave</code>
      ones. The type is constructed in such a way that variables of this type
      are able to hold <emphasis><?xxe-sn 2f0cduzin5j -wunr7fl0rw8m?>predicate</emphasis>'s
      arguments. Type inference works as follows:</para>

      <itemizedlist>
        <?xxe-sn 2f0cduzin5j -wunr7fl0rw8l?>

        <listitem>
          <?xxe-sn 2f0cduzin5j -wunr7fl0rw8k?>

          <para><?xxe-sn 2f0cduzin5j -wunr7fl0rw8j?>If a predicate has only
          one argument then a constructed type is a type of this argument:
          <code><?xxe-sn 2f0cduzin5j -wunr7fl0rw8i?>int</code>,
          <code><?xxe-sn 2f0cduzin5j -wunr7fl0rw8h?>string</code>, variant or
          tuple.</para>
        </listitem>

        <listitem>
          <?xxe-sn 2f0cduzin5j -wunr7fl0rw8g?>

          <para><?xxe-sn 2f0cduzin5j -wunr7fl0rw8f?>A constructed type is a
          record in case of several arguments.</para>
        </listitem>

        <listitem>
          <?xxe-sn 2f0cduzin5j -wunr7fl0rw8e?>

          <para><?xxe-sn 2f0cduzin5j -wunr7fl0rw8d?>Predicates correspond to
          variants in a constructed type.</para>
        </listitem>
      </itemizedlist>

      <para><?xxe-sn 2f0cduzin5j -wunr7fl0rw8c?>An example; Transcend
      facts:</para>

      <programlisting><?xxe-sn 2f0cduzin5j -wunr7fl0rw8b?>person("John", 1962).
person("Bill", 1961).</programlisting>

      <para><?xxe-sn 2f0cduzin5j -wunr7fl0rw8a?>The Brute side:</para>

      <programlisting xml:id="SlaveTypes1"><?xxe-sn 2f0cduzin5j -wunr7fl0rw89?>name="tests/transcend.cpp: Transcend.Doc_SlaveTypes1", lines=15
PersonNative = type {string, int}.
Person = type slave person.</programlisting>

      <para><?xxe-sn 2f0cduzin5j -wunr7fl0rw88?>In the example above the types
      <code><?xxe-sn 2f0cduzin5j -wunr7fl0rw87?>PersonNative</code> and
      <code><?xxe-sn 2f0cduzin5j -wunr7fl0rw86?>Person</code> are
      equivalent.</para>
    </section>
  </section>

  <section>
    <?xxe-sn 2ey6qxf8um8 19?>

    <title><?xxe-sn 2ey6qxf8um8 1a?>Variants</title>

    <para><?xxe-sn 2ey6qxf8um8 1b?>Sometimes it is useful for a variable to
    have an ability to hold values of different types depending on some
    conditions, in other words to have a <emphasis><?xxe-sn 2ey6qxf8um8 1c?>variant
    type</emphasis>. An example:</para>

    <programlisting xml:id="Variants1"><?xxe-sn 2ey6qxf8um8 1d?>name="tests/ast.cpp: AST.Doc_Variants1"
Color = type variant {
  White, Black, Magenta, 
  CustomColor:: {r:: int, g:: int, b:: int}
}.

draw = function:: int 
{
  clrBorder = Black():: Color.
  clrBackground = CustomColor(50, 50, 50):: Color.
  
  drawRectangle({0, 0, 100, 100}, clrBorder, clrBackground)
}</programlisting>
  </section>

  <section>
    <?xxe-sn 26yv439af40 ei?>

    <title><?xxe-sn 26yv439af40 ej?>SWITCH VARIANT Statement</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 a 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 the <emphasis><?xxe-sn 2ey6qxf8um8 1e?>condition</emphasis>
        expression withing case branches.</para>
      </listitem>

      <listitem>
        <?xxe-sn 26yv439af40 es?>

        <para><?xxe-sn 26yv439af40 et?><emphasis><?xxe-sn 26yv439af40 eu?>guard</emphasis>
        Name of a 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>
        Code block to execute in case of the matched variant. The
        <emphasis><?xxe-sn 2ey6qxf8um8 1f?>condition</emphasis> expression's
        content is referred to by <emphasis><?xxe-sn 2fadpf0i3zr -wunr7fl0rw8t?>alias</emphasis>
        within the branch.</para>
      </listitem>
    </itemizedlist>

    <para><?xxe-sn 26yv439af40 ey?>Variant variables require special means to
    test which exactly variant they contain at any given moment as well as to
    access it. Usually, languages that support variant types(ADT) solve this
    problem be means of <emphasis><?xxe-sn 2ey6qxf8um8 1g?>pattern
    matching</emphasis>. Xreate intentionally does not support pattern
    matching since it is depends on parameters order, which is plainly
    unacceptable; besides, it's hardly usable in case of a large amount of
    parameters. Instead, Xreate supports special syntax to <emphasis><?xxe-sn 2ey6qxf8um8 1h?>unwrap</emphasis>
    a variable's content using <code><?xxe-sn 2ey6qxf8um8 1i?>switch variant</code>
    statement.</para>

    <para><?xxe-sn 26yv439af40 f0?>An example:</para>

    <programlisting xml:id="VariantsSwitch1"><?xxe-sn 26yv439af40 f3?>name="tests/ast.cpp: AST.Doc_VariantsSwitch1",lines=15
Month = type variant {
  MonByName  :: {name:: string}, 
  MonById    :: {id:: int}
}.

nextMonth = function(month:: Month):: Month 
{
  switch variant(month):: Month 
  case (MonByName) 
  {
    monthName = month["name"]:: string. //here month has {name:: string}  type

    MonByName(nextMonthByName(monthName))
  }

  case (MonById)
  {
    monthId = month["id"]:: int.        //here month has {id:: int} type

    if(monthId == 11):: Month 
      { MonById(0) }
    else 
      {MonById(monthId + 1)}
  }
}</programlisting>

    <para><?xxe-sn 26yv439af40 f4?>The function <code><?xxe-sn 2ey6qxf8um8 1j?>nextMonth</code>
    computes the next month after a given one. The parameter <code><?xxe-sn 2ey6qxf8um8 1k?>month</code>
    can't be directly accessed due to being of a variant type; hence, It
    should be <emphasis><?xxe-sn 26yv439af40 f8?>unwrapped</emphasis> before
    using. As seen in this example, Xreate silently defines a new variable
    with the same name <code><?xxe-sn 2ey6qxf8um8 1l?>month</code> which holds
    an unwrapped content for each <code><?xxe-sn 2ey6qxf8um8 1m?>switch variant</code>'s
    branch independently.</para>
  </section>

  <section>
    <?xxe-sn 2fds09lgw74 m?>

    <title><?xxe-sn 2fds09lgw74 n?>Versions</title>

    <synopsis><?xxe-sn 2fds09lgw74 o?>//identifier// [**{** //version// **}**]</synopsis>

    <itemizedlist>
      <?xxe-sn 2fds09lgw74 p?>

      <listitem>
        <?xxe-sn 2fds09lgw74 q?>

        <para><?xxe-sn 2fds09lgw74 r?><emphasis><?xxe-sn 2fds09lgw74 s?>version</emphasis>
        Number to specify the identifier's version.</para>
      </listitem>
    </itemizedlist>

    <para><?xxe-sn 2fds09lgw74 t?>Versions is a language construct to deal
    with mutable data. An example: </para>

    <programlisting xml:id="Versions1_1"><?xxe-sn 2fds09lgw74 v?>name="tests/ast.cpp: AST.Doc_Versions1"
Date = type {year:: int, month:: string}.

test = function::                        Date; entry
{
 x{0} = {year = 1953, month = "March"}:: Date.
 x{1} = x{0} + {month = "February"}::    Date. //updates a single record's field

 x{1} //returned value
}</programlisting>

    <para><?xxe-sn 2fds09lgw74 w?>In the example above <code><?xxe-sn 2fds09lgw74 x?>x{0}</code>,
    <code><?xxe-sn 2fds09lgw74 y?>x{1}</code> are different versions of the
    same variable. This is a simple trick with the idea that for all intents
    and purposes <code><?xxe-sn 2fds09lgw74 z?>x{0}</code>, <code><?xxe-sn 2fds09lgw74 10?>x{1}</code>
    behave like different variables but really aren't. All analyses treat them
    as different immutable variables, yet the compiler actually uses the same
    memory address for them making this an update of a variable. It is a hint
    from a developer that the only one version of a variable should be
    available at any given time. The only analysis that knows the truth is the
    versions analysis. It is responsible for code validation in order to make
    sure that there is no expression that uses an outdated/unknown/unreachable
    variable's version. An another (counter)example:</para>

    <programlisting xml:id="Versions1_2"><?xxe-sn 2fds09lgw74 11?>COUNTEREXAMPLE, name="tests/ast.cpp: AST.Doc_Versions1"
x{0} = 8:: int. 
x{1} = x{0} + 10:: int. 
y = x{0} + x{1} :: int. //invalid code: uses several versions</programlisting>

    <para><?xxe-sn 2fds09lgw74 12?>The versions analysis builds a variables'
    liveliness graph to track versions usage and reveal situations when it's
    impossible to compute an expression due to the fact that it refers to an
    (possibly) outdated or unreachable version.</para>
  </section>

  <section>
    <?xxe-sn 2ey6qxf8um8 1t?>

    <title><?xxe-sn 2ey6qxf8um8 1u?>Records</title>

    <para><?xxe-sn 2ey6qxf8um8 1v?>Record's elements(fields) are denoted by
    strings in order to access the field's value. This gives a possibility to
    use variables to reference fields. Such references are statically resolved
    during <link xlink:href="/d/concepts/interpretation/"><?xxe-sn 2ey6qxf8um8 1w?>Interpretation</link>.
    An example:</para>

    <programlisting xml:id="RecField1"><?xxe-sn 2ey6qxf8um8 1x?>name="tests/ast.cpp: AST.Doc_RecField1"
Employee = type {
  name ::     string,
  surname ::  string,
  signature:: string
}.

test = function:: string; entry
{
  employee = getAnyEmployee():: Employee.
  primaryKey = "surname":: string.
  
  employee[primaryKey]
}</programlisting>

    <para><?xxe-sn 2ey6qxf8um8 1y?>In Xreate the left side of any assignment
    is always an identifier, hence there is special syntax to update one(or
    more) record's fields. An example:</para>

    <programlisting xml:id="RecUpdate1"><?xxe-sn 2ey6qxf8um8 1z?>name="tests/ast.cpp: AST.Doc_RecUpdate1"
Day = type {
  year:: int,
  month:: string,
  day:: int
}.

test = function:: Day 
{
  tomorrow

  today = {year = 1936, month = "July", day = 21}:: Day. 
  tomorrow = today + {day = 22}:: Day. 
}</programlisting>
  </section>
</chapter>
<?xxe-revisions
#12 2019-05-18T10:27:21Z pgess
#11 2019-05-16T15:13:16Z pgess
1sPEAAABgrx7AB6CqmEAAA0Kc4KgXyMMExVzDFOJVQCCpF+8GXuB9w0=

#10 2019-05-14T16:34:55Z pgess
1sPEAAABgqphAIIggqpoAAaBG3dBQUFBQWJzv1AjBCMEE4RkgwQTCmOBOgEBE2xTiFwBATMHQwdj
CmMMQwkzNlOhIiMFY4FBAQFDB0OMaRMEYw1jgSeTDlObCxMEM4Eokw5jBlODUoMEQwtDgTYjGzOO
fHMEU4EoczczgVoBAVMKEwkTY1O5bmMOU5h0gwUzgSmTDlOCDIMOMwczgUEBARMHEwUTBGOBADMH
/FMEYwQzBTOaMwDNRoGSNL9Ua7sthG6Nd4IllD7zLaMjhFm1Io50iz6BhXChJLgGgUe6Y65QjHdj
gTK3apsNY4lggTlrjBWDXYUrgU7qjn5ogVyTGbBmjgCCT4GjFLl4RJh2Y4E0MYJCgh3EPLFuiV2B
TYGnTJAbgZsahG2bCYkd
#9 2019-05-11T15:02:16Z pgess
1sPEAAABgqpoAD+CqnAAAB8Zc4H2HhMEE4IfQwRTgUFDCWMFgwSDEBMWQxBTEDOwEgCB/lCB9iCe
IoIhjnGFA1BBhiuDdtNXghU=
#8 2019-05-11T12:29:03Z pgess
1sPEAAABgqpwACuCmDkAABQQc4H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