Simple examples of |
Let us start with the famous “hello world” example, which
is written as follows in
|
By default, only very few types are available in
The example program can be run in two ways: by compiling it using the
Assuming that the above program was saved in a file hello_world.mmx, we may compile and execute the program in a shell session as follows:
Shell] | mmc hello_world.mmx |
Shell] |
./hello_world |
Hello world!
Shell] |
Alternatively, we may directly run the program in the
Welcome to Mathemagix
1.0.1
This software falls under the GNU
General Public License
It comes without any warranty
whatsoever
http://www.mathemagix.org
(c) 2010-2012
Mmx] |
include "hello_world.mmx" |
Hello world!
Mmx] |
When including files with external C++ functionality for the first time in the interpreter, the interpreter first has to compile some glue in order to use this functionality. This happens in particular for the file basix/fundamental.mmx. Whenever the interpreter is compiling some glue, it displays a message which disappears as soon as the compilation is complete.
Another classical example is the computation of Fibonacci sequences. A simple implementation using a recursive function goes as follows:
|
Notice that the programmer has to specify explicit types for the
arguments and return type of the function. In our example both the
argument and the return value are machine integers of type
|
One more involved example is to provide a generic implementation of the merge sort algorithm:
|
This routine
|
yield the output
[1, 2, 3, 4, 4, 5, 7] ["alice", "bob", "carl"]