-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rml
137 lines (106 loc) · 2.49 KB
/
test.rml
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
print-ln "hello world"
local foo = 1
local var = fun => nil
local jazz = "test"
local {x y} = '(1 2)
assert (== foo 1)
assert (== jazz "test")
assert (not (== jazz "t3st"))
assert (== x 1)
assert (== y 2)
assert (not (== var nil))
assert ((== (var) nil))
assert (not (> 1 2 3 4))
assert (< 1 2 3 4)
assert (<= 1 1 2 2 3 4)
assert (> 4 3 2 1)
assert (not (< 4 3 2 1))
assert-eq 15 (apply + '(1 2 3 4 5))
print-ln (gensym)
assert (!= (gensym) (gensym))
local check = fun{* args} => print-ln args
check 1 2 3 4 5
check 1 2
check 1
(check)
local check2 = fun
(1 2) => print-ln "let me see u one, two step"
{+ args} => print-ln args
else print-ln "no args"
check2 1 2 3 4 5
check2 1 2
check2 1
(check2)
local foo = fun x =>
print-ln x
+ x 1
print-ln "woo " (foo 1)
print-ln (not true)
print-ln 'foo
print-ln `(1 2 3)
print-ln `(1 2 ,(foo 2))
print-ln `(1 2 ,@'(3 4))
local incrBy = fun x =>
fun y =>
+ x y
local incr = incrBy 2
assert-eq 3 (incr 1)
assert-eq 4 (incr 2)
local mac = macro x => `(print-ln ,x)
mac 1003
local closure = fun x =>
local a = fun y => + x y
local b = fun y => set! x y
`(,a ,b)
local (a b) = closure 1
assert-eq 2 (a 1)
b 2
assert-eq 3 (a 1)
local check-self = fun =>
print-ln "check-self " check-self
(check-self)
global one-hundred = 100
print-ln one-hundred
import type
assert (type/nil? nil)
assert (not (type/nil? 1))
assert (type/string? "foo")
assert (not (type/string? 1))
import String
assert-eq 4 (String/length "test")
import text
print-ln (text/category 't')
assert-eq "test" (text/lowercase "TEST")
assert-eq "TEST" (text/uppercase "test")
assert (text/lowercase? 't')
assert (not (text/lowercase? 'T'))
assert-eq 'Int (type/of 0)
assert-eq 'Char (type/of 't')
assert-eq 'Symbol (type/of (type/of 0))
assert-eq 'native:GenCatData/Gc (type/of (text/category 't'))
local fail-tester = fun x =>
print-ln "this should print, but then we fail " x
fail 'failure-sym
with (fail = cancel)
fail-tester "test"
print-ln "this shouldn't print"
with {
fail = fun msg =>
print-ln "fail: " msg
cancel 'failure-sym
} fail "test"
local x = 0
with {
fresh = fun =>
local out = x
set! x (+ x 1)
out
}
local a = (fresh)
local b = (fresh)
assert-eq a 0
assert-eq b 1
print-ln a " " b
assert-eq 'failed (with (fail = fun() => cancel 'failed) (fail))
; FIXME: failing because of the missing pattern, somehow
; assert-eq 'failed (with (fail = fun => cancel 'failed) (fail))