Something went wrong. Try again.
A component based functional template language
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121component FunctionEmpty { let noop = fn () -> { }; noop()}component Function { let onePlusTwo = fn () -> { let one = 1; let two = 2; one + two }; onePlusTwo()}component FunctionCurried { let returns_one = fn () -> if (true) 1 else 2; let returns_returns_one = fn () -> returns_one; returns_returns_one()()}component FunctionScope { let trap = "123"; let globalSeed = 50; let minusOne = fn () -> { let n = 1; globalSeed - n }; let minusTwo = fn () -> { let n = 2; globalSeed - n }; minusOne() + minusTwo()}component FunctionArguments { let add = fn (a, b) -> a + b; let addOne = fn (arg) -> { let one = 1; add(arg, one) }; addOne(4) + addOne(9)}component FunctionTooManyArguments { let add = fn (a, b) -> a + b; add(4, 5, 6)}component FunctionTooFewArguments { let add = fn (a, b) -> a + b; add(4)}component FunctionClosure { let seed = 221; let adder = fn (a) -> { let id_a = fn () -> a; fn (b) -> { let partial = a + b; let final = fn (c, d) -> id_a() + partial + c + seed * d; final } }; adder(3)(7)(9, 2)}component RecursiveFunction { let fact_and_fib = fn (a, b) -> { let fibonacci = fn (n) -> { if (n <= 1) { n } else { fibonacci(n - 1) + fibonacci(n - 2) } }; let factorial = fn (n) -> { if (n <= 1) { 1 } else { n * factorial(n - 1) } }; factorial(a) + fibonacci(b) }; fact_and_fib(5, 9)}component MutuallyRecursiveFunction { let is_even = fn (i) -> { if (i == 0) { true } else { is_odd(i - 1) } } and is_odd = fn (i) -> { if (i == 0) { false } else { is_even(i - 1) } }; is_even(2)}