2024-02-19 02:54:02 +07:00
|
|
|
; declare a module
|
2024-02-16 02:07:52 +07:00
|
|
|
module main
|
|
|
|
|
2024-02-19 02:54:02 +07:00
|
|
|
; no explicit export so everything in this module is exported
|
|
|
|
export one, two
|
2024-02-16 02:07:52 +07:00
|
|
|
|
2024-02-19 02:54:02 +07:00
|
|
|
; no import
|
|
|
|
import a
|
|
|
|
import a only name, name
|
|
|
|
import a as change_name
|
2024-02-16 02:07:52 +07:00
|
|
|
|
2024-02-19 02:54:02 +07:00
|
|
|
; declare a variable
|
|
|
|
one : number = 1
|
|
|
|
|
|
|
|
; declare a variable that is computed
|
|
|
|
; places a burden on the runtime
|
|
|
|
two : number = one + 1
|
|
|
|
|
|
|
|
; tt : bool = true
|
|
|
|
|
|
|
|
; types can be named, alias
|
|
|
|
|
|
|
|
; using tuple or record or enum
|
|
|
|
type coordinates_tuple = tuple (number, number)
|
|
|
|
; type coordinates_record = record { x : number , y : number }
|
|
|
|
|
|
|
|
coordinates_as_tuple : coordinates_tuple = tuple (1, 2)
|
|
|
|
; coordinates_as_record : coordinates_record = record { x : 1 , y : 2 }
|
|
|
|
|
|
|
|
; function definition is structured the same
|
|
|
|
void : fn => number = function is
|
|
|
|
let x = 1 in
|
|
|
|
1
|
|
|
|
|
|
|
|
return_false : fn => bool = function is
|
|
|
|
false
|
|
|
|
|
|
|
|
increment : fn number => number = function x is
|
|
|
|
x + 1
|
|
|
|
|
|
|
|
is_even : fn number => bool = function x is
|
|
|
|
if x % 2 then true else false
|
|
|
|
|
2024-03-29 14:45:17 +07:00
|
|
|
; invoke a function by name
|
2024-02-19 02:54:02 +07:00
|
|
|
bruh : number = increment(one)
|
2024-03-29 14:45:17 +07:00
|
|
|
|
|
|
|
; invoke a lambda function
|
|
|
|
bruh1 : number = (function x is x)(1)
|
|
|
|
|
|
|
|
; invoke a calculation returns a function
|
|
|
|
bruh2 : fn bool => number = function cond is
|
|
|
|
(if cond then
|
|
|
|
function x is x + 1
|
|
|
|
else
|
|
|
|
function x is x + 2
|
|
|
|
)(0)
|
2024-03-29 16:20:34 +07:00
|
|
|
|
|
|
|
|
|
|
|
main : fn => number = function is
|
|
|
|
1
|