Using the Mathemagix interpreter

This section describes how to use the mathemagix interpreter mmi available from the mmcompiler package.

1.Terminal interface

From a terminal, the mathemagix interpreter is launched with the following command:

$ mmi
--------------------------------------------------------------
|:*)              Welcome to Mathemagix 1.0.2             (*:|
|------------------------------------------------------------|
|  This software falls under the GNU General Public License  |
|          It comes without any warranty whatsoever          |
|                http://www.mathemagix.org                   |
|                      (c) 2010-2012                         |
--------------------------------------------------------------
1] 

At first run the following message should last several seconds, according to the performances of your computer:

mmi: compiling glue...

This means that the fundamental librairies are being compiled. At next run, the message still appears but lasts just the time needed to check that these compiled libraries are up to date.

Whenever the interpreter has been compiled with the GNU readline library, several shortcuts are available such as

For more information and customization of the keyboard interface, please refer to the documentation of the GNU readline library.

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.

1] 1+1
2
2] 1+1;
3] 

In order to quit the interpreter one can type [Ctr-d], or call the function exit that takes the return value of the mmi command as an argument.

1] exit 0

2.Color mode

For a short list of terminals (xterm, xterm-color, xterm-256color), the color mode of the interpreter can be activated by adding the following option to the command line:

$ mmi --color
--------------------------------------------------------------
|:*)              Welcome to Mathemagix 1.0.2             (*:|
|------------------------------------------------------------|
|  This software falls under the GNU General Public License  |
|          It comes without any warranty whatsoever          |
|                http://www.mathemagix.org                   |
|                      (c) 2010-2012                         |
--------------------------------------------------------------
1]

The –color option can be activated by default by setting the global environment variable MMX_COLOR_MODE to yes. For instance, if your default shell is Bash, then you might want to add the following line to your $HOME/.profile file in order to get the color mode permanently:

export MMX_COLOR_MODE="yes"

In this case, colors can be punctually disabled as follows:

mmi --no-color

Supported terminals are specified in basix/src/formatting_port.cpp.

3.Other interpreter options

The behavior of the interpreter can be modified according to the following command line options:

–quiet

Disable printing the banner and prompt.

–quit

Quit the interpreter after replaying a session.

–replay

Replay the previous session.

–texmacs

Enable the TeXmacs interface (to be used by TeXmacs only).

–time

Display compilation and executing timings.

–type

Display types of computed expressions.

–verbose

Enable verbose mode.

The command line option –help summarizes the usage of mmi, and –version returns the current version of mmi.

The following options are passed to the compiler mmc for compiling dynamic librairies at runtime: –diff, –gdb, –keep-cpp, –no-cache, –no-warnings, –optimize, –timings, –verbose.

4.Builtin help command

Signatures and source locations of functions can be obtained via the help command as follows:

1] help infix +
+ : (Int, Int) -> Int --- mmx/basix/mmx/int.mmx:30:10
+ : (Double, Double) -> Double --- mmx/basix/mmx/double.mmx:33:10
+ : (Syntactic, Syntactic) -> Syntactic --- mmx/basix/mmx/syntactic.mmx:33:8
2] fib (n: Int): Int == if n <= 1 then 1 else fib (n-2) + fib (n-1)
3] help fib
fib : Int -> Int --- /Users/lecerf/.mathemagix/mmi/input_2.mmx:0:43

The latter source location corresponds the actual file where the input command is temporarily saved in. Help on types is also available:

5] help Vector
Vector : Type -> Class --- mmx/basix/mmx/vector.mmx:15:8

5.File inclusion

File inclusion is performed via the include function, as for the compiler. If the file to be included or one of its dependencies contains foreign declarations, for importing or exporting C++ functions, then the necessary dynamic librairies are automatically compiled and loaded. During the compilation the message mmi: compiling glue... is displayed. This compilation might take time, but it is only performed once.

1] include "numerix/integer.mmx"
2] 40!
815915283247897734345611269596115894272000000000

In case you are sure that all the dynamic libraries you are going to use in an interpreter session are already compiled then you might want to use the –no-glue option in order to discard checking if these dynamic libraries are up to date.

6.Low level debugger

If the compiler and interpreter have been compiled with passing the –enable-verify option to the configure script, then a low level debugger is made available by adding –exe-debugger to the mmi command. The features of the debugger are rather limited but are essentially useful to understand casual bugs, and to display the actual builtin C++ types being used. The interactive commands of this debugger are the following:

I

set interactive mode.

i

unset interactive mode.

E

set display of expressions.

e

unset display of expressions.

V

set display of values.

v

unset display of values.

n

go directly to next step.

s

step into the intermediate.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License. If you don't have this file, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.