
\section{Basic Data Types}
Rascal has a generic subsystem, which supports integers, doubles,
strings and matrices.
\subsection{Integers and Doubles}
Simple numbers are being interpreted as integers, which in this version of
Rascal are represented as integers on the underlying computer architecture.
No rounding errors will occur, but undetected overflows may occur.

Using double precision floating-point numbers overcomes this problem, but
rounding errors may occur. A number is being interpreted as a floating-point
number when there is a decimal-point within or at the end of the number
and/or an exponent. As an example {\tt 1.234e+12} represents $1.234\cdot
10^{+12}$. Be warned that there is no exact representation for $0.1$ and
many many other numbers in binary floating-point representations.

All operands like {\tt +,-,*,/,\^{ },\%{ }} are defined for integers and doubles,
together with standard functions {\tt sin, cos, tan, cot, asin, acos,
atan, acot, sinh, cosh, tanh, coth, asinh, acosh, atanh, acoth, log, exp,
sqrt, sqr}. 
A postfix {\tt !} computes the factorial of the operand (currently just in integer).

The values can be compared using the operators {\tt ==,!=,<,<=,>,>=},
logical expression can be connected using {\tt \&,|} and the logical negation
{\tt \~{ }}.  

\subsection{Strings}
Mostly strings are used internally, as an example all data-types have a
function called {\tt output} which defines how values of that type can be
printed on the screen.

Besides strings can be used as "evaluation variable": As all the
standard operators and functions are also defined for strings, one can
determine the expression Rascal would evaluate if the argument only
had been a real value.

Strings are enclosed in quotes:

\begin{lyxcode}
>f(x)=x*x+2*x;

>f(f("y"))

~"y*y+2*(y)*y*y+2*(y)+2*(y*y+2*(y))"

>strlen(f(f("y")))

~49
\end{lyxcode} 

But the operators {\tt ==,!=} are still used to compare two strings.
The {\tt strlen} function returns the length of the string.

\subsection{Generic Matrices and Vectors}

In Rascal vectors are just matrices with either just one row or one column.
You can enter a matrix by using brackets, where values within a line are
separated by spaces, lines are separated by semicolons. matrices of same size
can be added and subtracted using the usual operators:

\begin{lyxcode}
>A=[1 2;3 4;5 6]

~[1 2;3 4;5 6]

>B=[-3 -4;2 7;2 9]

~[-3 -4;2 7;2 9]

>A+B

~[-2 -2;5 11;7 15]

>A-B

~[4 6;1 -3;3 -3]

>rows(A)

~3

>cols(A)

~2

>size(A)

~3
\end{lyxcode}

Scalars can be multiplied to the matrices and two matrices can be multiplied
if the number of columns of the first matches the number of rows of the
second. Dividing by a matrix means multiplying with the inverse, of course
this is only defined for quadratic matrices. The functions {\tt rows, cols,
size} return the number of rows, columns and maximum of the two values of a
matrix or vector.

Types using the matrix inversion must be able to be compared to integers. If
there is no inverse, an empty matrix is being returned. You may compute the
determinant using the {\tt det} function.

\begin{lyxcode}
>[1 2]*[3;4] 

~[11]

>[1;2]*[3 4]

~[3 4;6 8]

>A=[1 3;4 13];

>det(A)

~1

>1/A

~[13 -3;-4 1]

>[2 0;0 3]/A

~[26 -6;-12 3] 

>
\end{lyxcode}

The cells of matrices can be of any type; here an example for an integer,
double, matrix, string matrix:
\begin{lyxcode}
>A=[1 2.34;[1 2;3 4] "hu"];

>A(1,2)
 
~2.340000
\end{lyxcode}
Now $A$ looks like the following:
$$A=\left(\begin{array}{cc}
1&2.34\\
\left(\begin{array}{cc}
1&2\\
3&4
\end{array}\right)&"hu"
\end{array}\right)$$
And the value at cell 1,2 is 2.34.

The summation of matrices and scalars is defined as the addition between the
matrix and the identity of same size times the scalar.
Vector valued functions can be defined easily, also with multiple
arguments.

\begin{lyxcode}
>f(x)=[x*x;x+2];

>f(8)

~[64;10] 

>f([1 2;3 4]) 

~[[7 10;15 22];[3 2;3 6]]

>f[1 2;3 4]

~[[7 10;15 22];[3 2;3 6]]

>g(x,y,z)=[x+y*z x*z];

>g(12,-5,2)

~[2 24]

>
\end{lyxcode}

\section{Loops}

The support for loops is experimental- it is very likely that the syntax
will change in future releases.

Rascal supports C(++)-style loops to a certain extend. The syntax is

{\tt for( <initialization> ; <condition> ; <expression 1> ) <expression 2> }

First the initialization expression is being evaluated- this should be used
to initialize the variable used for the loop. If the given condition is true
then expression 2 and 1 are evaluated (in that order) until the condition is
false after the evaluation of 1. Have a look at this example:

\begin{lyxcode}
>sum=0;

>for(x=1;x<10;x++) sum=sum+x;

>sum

~4950
\end{lyxcode}

The above example computes the sum of the numbers between 0 and 10. If you
would like to see the intermediate results, leave out the semicolon at the
end of the for statement:

\begin{lyxcode}
>sum=0;for(x=1;x<10;x++) sum=sum+x

~1

~3

~6

~10

~15

~21

~28

~36
 
~45
\end{lyxcode}

In contrast to C(++) there is no "comma-operator" in rascal yet, thus you
cannot use it in for-statements. Sorry.

\section{Signals}

You can interrupt running computations in Rascal by sending a SIGINT signal-
just press CTRL-C. Rascal will then try to stop all computations. If you
press CTRL-C again before Rascal was able to get back to the interactive
shell, Rascal will terminate. 

If you press CTRL-C while you are in the interactive shell, Rascal will beep
you and terminate if you repeat your signal.

Thus if you "for"-statement doesn't seem to terminate or you were trying to
compute the factorial of "100000", just press CTRL-C and you won't lose you
work done before.
