| Using the |
This tutorial describes how to use the
The
mmx-light
If you use the interpreter in a textual context, several shortcuts can be very useful such as
Different modes are available:
Information about an object or a function can obtained with the command help:
Mmx]
help infix +
+ : (Generic, Vector (Generic)) -> Vector (Generic)(Native)+ : (Vector (Generic), Generic) -> Vector (Generic)(Native)+ : (Double, Double) -> Double(Native)+ : (Int, Int) -> Int(Native)
Mmx]
A quick description of the syntax of the language is available here.
A classical way to develop
f (n: Int): Int == {
if n < 2 then return n;
else {
mmout <<n<<"\n";
if n mod 2 = 0 then return f(n div 2);
else return f(3*n+1);
}
}
It can be used from the interpreter as follows:
Mmx]
include "mmxlight/step1.mmx"
Mmx]
f 57
57
172 86 43 130 65 196 98 49 148 74 37 112 56 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2
1
Mmx]
The interpreter can be used directly with a file:
mmx-light step1.mmx
Mathemagix files can also be used as scripts, as shown in this example:
#!/usr/bin/env mmx-light
m : Double := 0.0;
for i in 1..#argv do m:= m + as_double argv[i];
mmout<<"Mean: "<< m/(#argv-1)<<"\n";
If this code is put in a file, say mean, it can be used as follows:
chmod u+x mean
./mean 3.2 5.6 -1.7
Mean: 2.36666666667
provided that the command mmx-light is available.
The command to load and use the types and functions exported by an external library is use:
use "package";
Here the dynamic library libmmxpackage.so will be searched in the loading path (see variable LD_LIBRARY_PATH or DYLD_LIBRARY_PATH).
Under some Linux distributions you may face a problem with SELinux whenever it is in standard strict mode. Indeed SELinux will prevent you from loading Mathemagix's dynamic libraries. As a solution you can go to your administration / security menu and allow the use of shared libraries with Text Relocation. We strongly recommend you to refer to the SELinux documentation to really know what this change involves for the global security of your system.
The first time the shell is launched it creates a .mathemagix in the home directory. A warning is printed.
The file .mathemagix/etc/boot.mmx is automatically loaded at startup. This is the right place to customize the shell and to load the packages you frequently use. In order to load packages you can proceed as follows:
if supports? "numerix" then use "numerix";
if supports? "algebramix" then use "algebramix";
Prior to user's boot file a global boot file (usually /usr/local/etc/mathemagix/boot.mmx) is loaded. In case you wish to disable both boot files use the option –noboot within the mmx-light command.
Within an interactive session, ending a line with a ';' actually means finishing with a null instruction. As a consequence this extra ';' prevents from printing the output of the previous instruction.