tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

64 lignes · 1060 octetsBrut · Historique
1import std/io
2import std/list
3
4fn fib :: n
5{
6 if n < 2
7 {
8 n
9 }
10 else
11 {
12 fib (n - 1) + fib (n - 2)
13 }
14}
15
16// A tail-recursive loop must run in constant stack.
17fn count_to :: n acc
18{
19 if n == 0
20 {
21 acc
22 }
23 else
24 {
25 count_to (n - 1) (acc + 1)
26 }
27}
28
29// Non-tail recursion 100k deep.
30fn build :: n
31{
32 if n == 0
33 {
34 []
35 }
36 else
37 {
38 [n, ..build (n - 1)]
39 }
40}
41
42pub fn main :: -> () / <io>
43{
44 io.println (show (1 + 2 * 3 - 4 / 2 % 3))
45 io.println (show (fib 20))
46 io.println (show (count_to 1_000_000 0))
47 io.println (show (list.length (build 100_000)))
48 io.println (show (-7 / 2) <> " " <> show (-7 % 2))
49 io.println (show (1.5 * 2.0) <> " " <> show (10.0 / 4.0))
50 io.println
51 if 3 >= 3 && !(2 > 3) || False { "logic ok" } else { "logic broken" }
52 io.println ("con" <> "cat" <> show True)
53 let total = list.range 1 10 |> list.map fn x { x * x } |> list.sum
54 io.println ("sum of squares: " <> show total)
55}
56//> 5
57//> 6765
58//> 1000000
59//> 100000
60//> -3 -1
61//> 3.0 2.5
62//> logic ok
63//> concatTrue
64//> sum of squares: 385