Math¶
1#!/usr/bin/python -m mash
2
3# constants
4pi <- float 3.141592653589793
5
6# unary operators
7abs (x):
8 if $x >= 0 then
9 return $x
10 else
11 return math - $x
12
13
14fac (n):
15 if $n < 0 then fail
16
17 if $n == 0 then
18 return 1
19
20 return range $n |> product
21
22
23# binary operators
24add (a b): math a + b
25sub (a b): math a - b
26mul (a b): math a * b
27
28# reduction
29sum (x): echo $x |> reduce add 0
30product (x): echo $x |> reduce mul 1