Skip to content

VarunVF/mathfp-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MathFP

CI & Docs

MathFP is a functional, expression-oriented programming language designed for mathematical modeling and rapid prototyping. Built with Rust, it prioritizes safety and mathematical correctness.

Online Documentation

Features

  • Expression-First: Everything in MathFP is an expression, which allows for more elegant composition of logic.
  • First-Class Functions: Functions are first-class values. They can be passed as arguments and returned from functions or other expressions.
  • Rich Error Reporting: Detailed scanner and parser error messages, including line and column tracking.

Getting Started

Prerequisites

Installation

Clone the repository and build the project using Cargo:

git clone https://github.com/varunvf/mathfp-rs.git
cd mathfp-rs/
cargo build --release

Editor Support

A simple syntax highlighting extension for VS Code is available (located in editors/vscode/). Most editor themes should work alongside with this extension.

Usage

Run the REPL to start evaluating expressions:

cargo run

You can also run a script by passing the filename as an argument.

cargo run -- script.mfp

Language Syntax

Variable Bindings

Variables are declared using the := operator. A variable can only be declared once in the same scope.

x := 10; y := x * 5

Most variables can be modified using the = operator.

x = 2 * y

Conditionals

Any expression can be used in the then and else branches of an if-expression.

if y then (z := 1) else (z := 2)

If you omit the else branch but the condition is false, nil is implicitly returned.

res := if 0 then 5  // res is now nil

Functions

Functions use the |-> (maps-to) operator:

f := x |-> x * x
f(2)

Functions can have a more complex body with multiple statements.

The last expression is implicitly returned. Bindings created inside a function are locally scoped and do not affect their outer scope.

hypotenuse := a |-> b |-> {
    a2 := a * a;
    b2 := b * b;
    sqrt(a2 + b2)
}
hypotenuse(3)(4)

Builtins

Common math functions like sin and sqrt are defined as native functions, and can be used anywhere.

square := x |-> x * x;
square(sin(9)) + square(cos(9))

Development

Running Tests

Run the testing suite with cargo:

cargo test

Documentation

The project documentation is automatically updated on every push to main. View the online documentation

You can also view the local version by running:

cargo doc --open

About

A functional, expression-oriented math language implemented in Rust.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages