Skip to content

Repository files navigation

MontiFun

A functional programming language for the JVM. It allows for defining constants as well as functions.

This documentation is intended for modelers who use the languages. A detailed documentation for language engineers using or extending the languages is located here. We recommend that language engineers read this documentation before reading the detailed documentation.

An Example Model

montifun Math {

  // constant definition
  double PI = 3.141592653589793;

  // function definition
  int fibonacci(int n) =
    if n == 0 then 0 else (
      if n == 1 then 1 else
        fib(n - 1) + fib(n - 2)
    );

}

To define constants and functions, most (side effect free) expressions are supported.
Similarly, most types provided by MontiCore are available.

Command Line Tool

The command line tool of MontiFun provides functionality such as

  • parsing
  • coco-checking
  • pretty-printing
  • loading and storing symbol tables
  • a REPL (read-eval-print-loop) for interactive use (alpha)
  • code generation (alpha)

Building the Tool from Source

You can build the tool yourself. This requires

  • Java 21
  • Gradle 8.14

First, clone the repository:

git clone https://git.rwth-aachen.de/monticore/languages/montifun.git

Change the directory to the root directory of the cloned sources:

cd montifun

Then build the project using Gradle:

gradle build

You can now find the executable JAR file located at target/libs/MCMontiFun.jar.

Command Line Options

The command line tool can be executed with

java -jar MCMontiFun.jar <options>
Option Argument Description
-h, --help Prints the list of command line options.
-i, --input <files> (space separated) Processes the input artifacts. Without further options, they are only parsed.
-p, --path <directory> Sets the artifact path for imported symbols to be searched recursively for files ending in ".*sym". Defaults to the current working directory.
--pp, --prettyprint <files> (space separated, optional) Prints the input artifacts to stdout or into the provided files.
-c,--coco Checks the context conditions for the input artifacts.
-s, --symboltable <files> (space separated, optional) Prints the symbol tables of the input artifacts in the specified files.
-gen, --generate <directory> (optional) Generates Java classes from the input artifacts into the specified directory (alpha).
--interpreter Starts the interactive interpreter (REPL) (alpha). S. below.

REPL – Interactive Interpreter (alpha)

MontiFun provides a REPL (read-eval-print-loop).
It can be run using

java -jar MCMontiFun.jar --interpreter

It provides several commands starting with :

Command Argument Description
:help Prints all commands
:exit Exits the REPL
:import <filename> imports a montifun file
:vars lists all variables in the outermost frame
:funcs lists all functions
:imports lists all imports of Java-classes
:timing toggles timing information. This cannot be used for benchmarking!

Input lines start with >. Output is printed below.

One can write expressions to have them evaluated:

> 2 + 3
5

Constants can be defined:

> int age = 44;
> age + 1
45

Functions can be defined:

> int f(int n) = n > 0 ? f(n - 1) + n : 0;
> f(5)
15

MontiFun files can be imported in some (few!) cases (imports within the models are not supported).
These imports start with :. Here we import a file defining the function even.

> :import circularDependecy.mfun
> even(4)
true

Java classes can be imported. Note that these imports are without :.

> import java.util.List;
> List<int> l = [1,2];

An input can span multiple lines by ending the lines with \

> int f(int n) = n > 0 ? \
                 f(n - 1) + n : \
                 0;

Further Information

About

MontiFun is a functional programming language developed with the MontiCore language workbench.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages