The expressive language that compiles to PHP.

Patreon logo
Support Mammouth or become a sponsor on Patreon

Overview

Mammouth on the left, compiled PHP output on the right.
{{
# Variables and parameters are optionally typed
number    = 42
int typed = number
opposite  = true

# Object-oriented style
Array<String> strings = <String>["mammouth"]
echo strings[0].length

# Condition
number = if opposite then -42 else 13

# Existence
echo "I knew it!" if opposite?

# No need for `$` whether it's a variable or a function
square = int (int x) -> x * x
square(2)

fn Hello() ->
    echo 'Hello Mammouth'
Hello()

# Array
num_list = [1, 2, 3, 4, 5]

# Map
obj = {
    'square': square
    'cube':   fn (x) -> x * square(x)
}

# Array comprehensions
squares = (square(num) for num in num_list)

# Typed array comprehensions
squares = (square(num) for int num in num_list)
}}
<?php
// mammouth runtime and helper functions will be added here
// PHP look generally saller and compressed
$number = 42;
$typed = $number;
$opposite = TRUE;

$strings = array("mammouth");
echo strlen($strings[0]);

$number = $opposite ? -42 : 13;

if(isset($opposite)) {
  echo "I knew it!";
}

$square = function($x) {
  return $x * $x;
};
$square(2);

function Hello() {
  echo 'Hello Mammouth';
}
Hello();

$num_list = array(1, 2, 3, 4, 5);

$obj = array('square' => square, 'cube' => function($x) {
  return mammouth_call_method($x, "operator*", square($x));
});

$squares = call_user_func(function() {
  global $num, $num_list;
  $result = array();
  for($i = 0; $i < count($num_list); $i++) {
    array_push($result, $square($num_list[$i]));
  }
  return $result;
});

$squares = call_user_func(function() {
  global $num, $num_list;
  $result = array();
  for($i = 0; $i < count($num_list); $i++) {
    array_push($result, $square($num_list[$i]));
  }
  return $result;
});
?>
<p><?php
echo "mammouth";
$str = array("Mammouth");
echo strlen($str[0]);
?></p>