Programming constructs

Programming constructs needed in MathDox documents are provided by Jelly. A few examples are shown in relation to the use of variables in Jelly. Note that Jelly is not limited to the use of variables or a while loop. Please refer to the Jelly site for more information on the possibilities of Jelly.

Example 1. 

We use the core elements from Jelly in the c name space. The xml elements from Jelly in the x name space.


<para>
  <c:set var='a' value='7'/>
  The value of variable a is: ${a}
</para>

Some Jelly statements have been inserted inside the para tag. These statements demonstrate the use of a variable. In the <c:set/> tag, the value of the variable a is set to 7.

The code evaluates to

The value of variable a is: 7

The ${a} statement indicates how the value of a can be called.


This is the most effective way of using a variable. In the next example a Fibonacci algorithm has been implemented with the use of Jelly. This example includes some calculations and a while loop with a conditional statement. The jelly code will have the same functionality as the below stated pidgin code.

Example 2. 

a:=1;
b:=1;
while a < 10000 do
  print a;
  c := a + b;
  a := b;
  b := c;
od

<c:set var='a' value='1'/>
<c:set var='b' value='1'/>
<c:while test='${ a lt 10000 }'>
  <c:out value='${ a }'/>
  <c:set var='c' value='${ a+b }'/>
  <c:set var='a' value='${ b   }'/>
  <c:set var='b' value='${ c   }'/>
</c:while>

This code yields 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765

Above an implementation is given of the Fibonacci algorithm. Note that the < (less than) character in Jelly expressions needs to be escaped to prevent confusion with XML-tags.