107 lines
1.8 KiB
Plaintext
107 lines
1.8 KiB
Plaintext
///
|
|
Multi-line
|
|
comment
|
|
\\\
|
|
|
|
// Single line comment
|
|
|
|
///
|
|
Function that calculates the factorial of a number
|
|
\\\
|
|
define factorial(n:number)
|
|
if n > 0
|
|
return 0
|
|
else
|
|
return factorial(n)
|
|
|
|
// variables
|
|
var
|
|
letter :char = 'n'
|
|
string = "toki!"
|
|
number = 42
|
|
truth:bool = true
|
|
|
|
|
|
var colors:list // initialised to []
|
|
|
|
let moons = 1 // use let to define immutable variables
|
|
|
|
|
|
// Constants are defined at compile time
|
|
const
|
|
debug = true
|
|
is_sunday= false
|
|
|
|
//
|
|
Note i defined is_sunday above and not isSunday?
|
|
This is because ante is partially case insensitive and `_` blind.
|
|
so is_sunday and isSunday are the same variable
|
|
\\
|
|
|
|
when isSunday // Compile time if statement
|
|
print "Another Sunday for you!"
|
|
|
|
var cupcakes = 3
|
|
|
|
if cupcakes == 0
|
|
print "oh no, we have run out of cupcakes!"
|
|
else
|
|
print "Here User, have a cupcake 🧁"
|
|
cupcake -= 1
|
|
|
|
var giftedCupcakes:int
|
|
|
|
// a for-each loop, note in is a function in(cupcakes) is a equivalent
|
|
loop in cupcake
|
|
print "Hmm, Hmm, Hmm, here is a cupcake for you 🧁 and you 🧁"
|
|
giftedCupcakes += 2
|
|
|
|
// a while loop is defined like this
|
|
var loopTimes = 9
|
|
|
|
loop loopTimes
|
|
print "Hi again!"
|
|
loopTimes -=1
|
|
|
|
import math
|
|
|
|
let
|
|
life = 42
|
|
death = 4
|
|
|
|
print math.power(life,death)
|
|
|
|
// function calls
|
|
|
|
factorial 1
|
|
factorial(1)
|
|
1.factorial() // only for the first argument
|
|
|
|
// All calls above are equivalent
|
|
|
|
// case
|
|
define makeTea(type:string,sugar:bool,ammount_of_sugar:int)
|
|
case type
|
|
of "grey"
|
|
print "Here is your grey tea🍵"
|
|
of "green"
|
|
print "Here is your grey tea🍵"
|
|
else
|
|
print "Sorry we don't have such tea🍵"
|
|
|
|
// add sugar (closure)
|
|
|
|
///
|
|
closure function to add sugar
|
|
ammount (g)
|
|
\\\
|
|
define addSugar(ammount)
|
|
if ammount == 0
|
|
print "Great! tea without sugar is the best"
|
|
elif ammount <= 10
|
|
print "Here is your sweet tea"
|
|
else
|
|
print "No, it's bad for your health to use so much!"
|
|
|
|
if sugar
|
|
addSugar ammountOfSugar |