code / tomo

Lines41.3K C23.7K Markdown9.7K YAML5.0K Tomo2.3K
7 others 763
Python231 Shell230 make212 INI47 Text21 SVG16 Lua6
(36 lines)
1 func make_adder(x:Int -> func(y:Int->Int))
2 return func(y:Int) x + y
4 func suffix_fn(fn:func(t:Text->Text), suffix:Text -> func(t:Text->Text))
5 return func(t:Text) fn(t)++suffix
7 func mul_func(n:Int, fn:func(x:Int->Int) -> func(x:Int->Int))
8 return func(x:Int) n*fn(x)
10 func main()
11 >> add_one := func(x:Int) x + 1
12 assert add_one(10) == 11
14 >> shout := func(msg:Text) say("$(msg.upper())!")
15 >> shout("hello")
17 >> asdf := add_one
18 assert asdf(99) == 100
20 >> add_100 := make_adder(100)
21 assert add_100(5) == 105
23 >> shout2 := suffix_fn(func(t:Text) t.upper(), "!")
24 assert shout2("hello") == "HELLO!"
26 >> abs100 := mul_func(100, Int.abs)
27 assert abs100(-5) == 500
29 # Test nested lambdas:
30 outer := "Hello"
31 fn := func()
32 return func()
33 return func()
34 defer say("$outer")
35 return outer
36 assert fn()()() == "Hello"