Commit | Line | Data |
---|---|---|
e4f737c3 DM |
1 | MalCore := Object clone do( |
2 | slurp := block(a, | |
3 | f := File with(a at(0)) | |
4 | res := f contents | |
5 | f close | |
6 | res | |
7 | ) | |
bea8cb29 | 8 | |
e4f737c3 DM |
9 | swapBang := block(a, |
10 | atom := a at(0) | |
11 | f := a at(1) | |
12 | args := MalList with(list(atom val)) appendSeq(a slice(2)) | |
13 | newVal := f type switch( | |
14 | "Block", f call(args), | |
15 | "MalFunc", f blk call(args), | |
16 | Exception raise("Unknown function type") | |
17 | ) | |
18 | atom setVal(newVal) | |
19 | newVal | |
20 | ) | |
bea8cb29 | 21 | |
e4f737c3 DM |
22 | NS := Map with( |
23 | "=", block(a, a at(0) == a at(1)), | |
bea8cb29 | 24 | |
e4f737c3 DM |
25 | "pr-str", block(a, a map(s, s malPrint(true)) join(" ")), |
26 | "str", block(a, a map(s, s malPrint(false)) join("")), | |
27 | "prn", block(a, a map(s, s malPrint(true)) join(" ") println ; nil), | |
28 | "println", block(a, a map(s, s malPrint(false)) join(" ") println ; nil), | |
29 | "read-string", block(a, MalReader read_str(a at(0))), | |
30 | "slurp", slurp, | |
bea8cb29 | 31 | |
e4f737c3 DM |
32 | "<", block(a, a at(0) < a at(1)), |
33 | "<=", block(a, a at(0) <= a at(1)), | |
34 | ">", block(a, a at(0) > a at(1)), | |
35 | ">=", block(a, a at(0) >= a at(1)), | |
36 | "+", block(a, a at(0) + a at(1)), | |
37 | "-", block(a, a at(0) - a at(1)), | |
38 | "*", block(a, a at(0) * a at(1)), | |
39 | "/", block(a, a at(0) / a at(1)), | |
40 | ||
41 | "list", block(a, a), | |
42 | "list?", block(a, a at(0) type == "MalList"), | |
43 | ||
44 | "empty?", block(a, a at(0) ifNil(true) isEmpty), | |
45 | "count", block(a, a at(0) ifNil(return(0)) size), | |
46 | ||
47 | "atom", block(a, MalAtom with(a at(0))), | |
48 | "atom?", block(a, a at(0) type == "MalAtom"), | |
49 | "deref", block(a, a at(0) val), | |
50 | "reset!", block(a, a at(0) setVal(a at(1)) ; a at(1)), | |
51 | "swap!", swapBang | |
52 | ) | |
bea8cb29 | 53 | ) |