Overview
m is a simple and intuitive programming language optimized for math-centric operations. It allows users to easily define functions, perform arithmetic, and loop over ranges in a concise, functional style. The language is designed with minimalism in mind—providing only the essential features required for mathematical computations. It will be a compiled language down to a bytecode, executed by a custom virtual machine.
Features
- Functional Style: m encourages functional programming principles, where functions are first-class citizens.
- Basic Arithmetic: Supports addition, subtraction, multiplication, division, and exponentiation.
- Variables: Use variables to store and manipulate data.
- Lists: Define and manipulate lists of numbers.
- Loops: Both while and for loops are supported for iteration.
- Built-in Standard Library: Access to standard computational and mathematical methods and constants.
- Alias System: Easily alias functions or constants for cleaner code.
- Simple Syntax: Easy-to-read syntax inspired by modern functional programming languages.
Basic Syntax
- Comments
Comments are written using #. Everything after # on a line is ignored.
This is a comment
- Printing Output
The > symbol is used to print output to the terminal.
> 5 + 5 # Outputs: 10
- Variable Definitions
Variables are declared using =. You can store the result of an expression in a variable.
x = 9 + 10
y = x + 1 # Valid
- Lists
Lists are created using square brackets [].
l1 = [1, 2, 3]
> l1 # Outputs: [1, 2, 3]
- Block scope
Scopes can be created using the curly brackets {}.
x = 1
{
y = 2
x = 2
}
> x # Outputs: 2
> y # error: 'y' is not defined
- Control flow
If-else statements are supported!
x = 1
if (x == 0): {
> 1
} else: {
> 2
}
- Function Definitions
Functions are defined using the syntax name(paramaters...): statement | { statement* }.
f(x): x + 1 # Function that adds 1 to x
g(x): {
a = x ** 2 + 3 * x + 5
a + 1 # Returns the result of the expression
}
- Loops
While Loop
while (x): x = f(x) # Continuously modify x until the condition is false
For Loop
For loops, by design, only support the for x in y syntax. To iterate, the range function must be used like in python.
for x in range(0, 10): {
> x # Outputs: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
}
- Namespaces
Namespaces allow functions and constants to be grouped together. They can be nested to allow for groups inside groups.
# Example Standard Library Namespace
namespace std {
namespace trig {
# ...
sin(x): {} # Computes and returns sin(x)
# ...
}
namespace constants {
# ...
PI = 3.1415 # ...
# ...
}
}
- Import Statements
Import statements begin with the !include "path" statement. They do this because I want them to. There is no particular reason to do this over include("path") or include "path".
!include "std/trig.m" # Import external libraries
!include "std/constants.m"
- Aliases
You can create aliases for functions or constants using the alias keyword.
alias sin std::trig::sin
alias PI std::constants::PI
> sin(PI / 2) # Equivalent to std::trig::sin(std::constants::PI / 2)
Log in or sign up for Devpost to join the conversation.