-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall.alisp
More file actions
64 lines (48 loc) · 1.23 KB
/
all.alisp
File metadata and controls
64 lines (48 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(bench 1
(test "int add" [42] 35.(+ 7))
(test "int sub" [35] 42.(- 7))
(test "fix" [42.00] (fix 42 2))
(test "fix add" [2.25] 1.5.(+ 0.75))
(test "fix sub" [2.25] 2.5.(- 0.25))
(test "string is" [T] "foo".(is "foo"))
(test "int iter" [0 1 2] (for 3))
(test "list iter" [1 3 5] (for i:[1 3 5] i))
(test "func" [42]
(func foo [] [Int] 42)
(foo))
(test "func args" [42]
(func foo [n:Int] [Int] n.(+ 7))
35.(foo))
(test "closure" [42]
(let [bar 42]
(func foo [] [Int] bar)
(foo)))
(test "anon func" [42]
(\ [] [Int] 42)
(_))
(test "tco" [[2 3 4]]
(func my-map [in:List t:Target] [List]
(func helper [in:Any out:Any] [List]
(if in.(nil?)
out.(reverse)
(helper:t in.(tail) (t in.(head)):out)))
(helper:t in NIL))
[1 2 3].(my-map (\ [Int] [Int] _.(+ 1))))
(test "multiple dispatch" [Int Any]
(func md [x:Int] [Meta] Int)
(func md [x:Any] [Meta] Any)
42.(md)
T.(md))
(test "thread join" [42]
(join (thread [Int] 42)))
(test "thread send" [42]
(let [t (thread [Int] inbox.(pop))]
t.(send 42)
t.(join)))
(test "queue iter" ['foo 'bar]
(let [t (thread [Int] (for m:inbox (if m.(is 'stop) (break) m)))]
t.(send 'foo)
t.(send 'bar)
t.(send 'stop)
t.(join)))
).(dump)