-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples
More file actions
112 lines (104 loc) · 1.71 KB
/
examples
File metadata and controls
112 lines (104 loc) · 1.71 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
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
>> + 1 (* 7 5) 3
39
>> (- 100)
-100
>>
()
>> /
/
>> (/ ())
Error: Cannot operate on non-number '/'.
>> list 1 2 3 4
{1 2 3 4}
>> {head (list 1 2 3 4)}
{head (list 1 2 3 4)}
>> eval {head (list 1 2 3 4)}
{1}
>> tail {tail tail tail}
{tail tail}
>> eval (tail {tail tail {5 6 7}})
{6 7}
>> eval (head {(+ 1 2) (+ 10 20)})
3
>> (eval (head {+ - + - * /})) 10 20
30
>> def {x} 100
()
>> def {y} 200
()
>> x
100
>> y
200
>> + x y
300
>> def {a b} 5 6
()
>> + a b
11
>> def {arglist} {a b x y}
()
>> arglist
{a b x y}
>> def arglist 1 2 3 4
()
>> list a b x y
{1 2 3 4}
>> def {add-mul} (\ {x y} {+ x (* x y)})
()
>> add-mul 10 20
210
>> add-mul 10
(\ {y} {+ x (* x y)})
>> def {add-mul-ten} (add-mul 10)
()
>> add-mul-ten 50
510
>> fun {add-together x y} {+ x y}
>> fun {unpack f xs} {eval (join (list f) xs)}
>> fun {pack f & xs} {f xs}
>> def {uncurry} pack
()
>> def {curry} unpack
()
>> curry + {5 6 7}
18
>> uncurry head 5 6 7
{5}
>> def {add-uncurried} +
()
>> def {add-curried} (curry +)
()
>> add-curried {5 6 7}
18
>> add-uncurried 5 6 7
18
>> > 10 5
1
>> <= 88 5
0
>> == 5 6
0
>> == 5 {}
0
>> == 1 1
1
>> != {} 56
1
>> == {1 2 3 {5 6}} {1 2 3 {5 6}}
1
>> def {x y} 100 200
()
>> if (== x y) {+ x y} {- x y}
-100
>> (fun {reverse l} {
if (== l {})
{{}}
{join (reverse (tail l)) (head l)}
})
>> (fun {nth l n} { if (== n 0) {head l} {nth (tail l) (- n 1)}})
>> (fun {has l x} { if (== l {}) {false} {if (== (eval (head l)) x) {1} {has (tail l) x}}})
>> (fun {last l} { if (== l {}) {{}} {if (== (tail l) {}) {head l} {last (tail l)}}})
>> (fun {and x y} {if (== x 0) {false} {if (== y false) {false} {true}}})
>> (fun {or x y} {if (== x 0) {if (== y 0) {false} {true}} {true}})
>> (fun {not x} {if (== x 0) {true} {false}})