Mamba

Logo

Documentation of the Mamba Language

View the Project on GitHub JSAbrahams/mamba_doc

🏠 Home

2 🛠 Features

2.1 🔀 Control Flow

2.1.1 Control Flow Expressions

If Expressions (or Statements)

If expressions are perhaps one of the most well known and universal programming constructs.

An if has either the form:

if <expression> then <expression or statement>

or:

if <expression> then <expression or statement> else <expression or statement>

For instance:

if b = 3 then print "b is three." else print "b is not three."

An if is an expression if:

So, an if expression has the form

if <expression> then <expression> else <expression>

An examplew would be:

def my_value = if a > 0 then 2E30 else 8E21

Match Expressions (or Statements)

A match can be used match based on the value of an expression. We can even match based on the type of the returned expression.

A match has the form:

match <expression> with { <expression> => <expression or statement> }

An example would be (if b is a number):

match b with
	1 => print "one"
	4 => print "four"
	5 => print "five"

We can also add a default case if:

match b with
	1 => print "one"
	4 => print "four"
	5 => print "five"
	_ => print "this is executed if we didn't match with any other"

A match is an expression if:

So, a match expression has the form:

match <expression> with { <expression> => <expression> }

With the additional requirement that we have a arm for every possible value of a given input type.