Something went wrong. Try again.
A component based functional template language
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 $ NO_COLOR="1" print_vm . Component <section> max(1, 5) = 5 min(1, 5) = 1 add_curry(1)(5) = 6 Math.fibonacci(9) = 34 Math.factorial(5) = 120 is_even(10) = true is_odd(10) = false 1 |> max(5) |> Math.factorial = 120 1 |> add_curry(5)() = 6 5 |> Math.factorial = 120 Math__Constants.pi = 3.1415 Map: 1 4 9 16 Map Pipe: 1 4 9 16 </section>
$ pincfmt ./data.pi template Component { let max = fn (a, b) -> { guard (a > b) else b; a }; let min = fn (a, b) -> { if (a < b) { a } else { b } }; let until = 5; let map = fn (array, f) -> { for (el in array) { if (min(el, until) == until) { continue; }; f(el) } }; let add_curry = fn (a) -> { fn (b) -> { a + b } }; let is_even = fn (i) -> { guard (i != 0) else true; is_odd(i - 1) } and is_odd = fn (i) -> { guard (i != 0) else false; is_even(i - 1) }; <section> max(1, 5) = {max(1, 5)} min(1, 5) = {min(1, 5)} add_curry(1)(5) = {add_curry(1)(5)} Math.fibonacci(9) = {Math.fibonacci(9)} Math.factorial(5) = {Math.factorial(5)} is_even(10) = {is_even(10)} is_odd(10) = {is_odd(10)} 1 |> max(5) |> Math.factorial = {1 |> max(5) |> Math.factorial} 1 |> add_curry(5)() = {1 |> add_curry(5)()} 5 |> Math.factorial = {5 |> Math.factorial} Math__Constants.pi = {Math__Constants.pi} Map: {map(1...10, fn (item) -> item ** 2)} Map Pipe: {1...10 |> map(fn (item) -> item ** 2)} </section> }
$ pincfmt ./library.pi library Math { 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) } }; } library Math__Constants { let pi = 3.1415; }