-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.yl
182 lines (149 loc) · 3.34 KB
/
test.yl
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
(print "-----------------simple py interop")
(+ 1 1)
(def foo 2)
foo
(def x 34)
x
(math/sin x)
(math/sin 2)
(op/add 1 2)
(def foo math/sin)
(foo x)
(+ 1 1)
(+ 1 2 3 4 5)
(def foo 10)
foo
(- 3 4)
(* 3 4)
(/ 3 4)
(+ 2 3)
(def foo-bar "test")
foo-bar
(def -- "test")
(def --> "test")
(- 1 3)
(/ 1 4)
(+ 1 3)
(+ 1 3 4 5)
(math/sin 33)
(def x 2)
x
(math/sin 33)
[1 2 3 4]
(def x [1 2 3 4])
x
(py-reduce + x)
(first x)
(+ 1 2 3 4)
(min 1 3 4 -1)
(= 1 2)
(= 1 1)
(print "-----------------If")
(def z 2)
(if (= z 2) (print "hello") (print "sorry"))
(def z 3)
(if (= z 2) (print "hello") (print "sorry"))
(print "-----------------Lambda")
((fn [x y] (op/add x y) 1 2))
(def f (fn [x y] (op/add x y)))
(f 1 4)
(f 1 8)
((fn [x](+ x 34)) 2)
(fn [x](+ x 34))
((fn [x y] (op/add x y)) 1 2)
((fn [x] (+ x 34)) 2)
(def foo (fn [x] (+ x 34)) )
(foo 9)
(def foo (fn [x y] (+ x 34 y)) )
(foo 9 8)
(def foo (fn [x y] (+ x y)) )
(foo 9 8)
(def x [1 2 3 4])
(first x)
(def foo (fn [x y] (+ x y)) )
((fn [x] (+ x 34)) 2)
(def bar (fn [x] (+ x 34)))
(bar 2)
(py-reduce + x)
(def incr (fn [i] (fn [x] (+ x i))))
((incr 5) 5)
(def incv (incr 5))
(incv 4)
(print "-----------------py-func using plysp func")
(def incr+ (fn [i] (fn [x y] (+ x y i))))
((incr+ 100) 4 5)
(def foo (incr+ 100))
(py-reduce (incr+ 100) x)
(py-reduce foo x)
(py-reduce + x)
(py-reduce / x)
(py-reduce * x)
(py-reduce - x)
(print "-----------------& rest")
(def bar (fn [x y & r] r))
(bar 1 2 4 8 9)
(print "-----------------& rest2")
(def bar (fn [x y & r] (- x y (py-reduce + r))))
(bar 1 2 4 8 9)
(print "-----------------type")
(type 1)
(def z 1)
(type z)
(type TypeError)
(dir TypeError)
(callable TypeError)
(isinstance (TypeError) TypeError)
(print "-----------------Do on one line")
(do (print "hello") (print "goodbye") (- 44 2))
;; input token error because of multiple lines
(do (print "hello")
(print "goodbye")
(- 44 2))
;; this is a comment.
(+ 2 2) ; this is a comment.
(print "-----------------------Try/Throw/Catch/Finally")
(try (throw ValueError "hello")
(catch Exception e
(print e)))
(try (/ 1 0)
(catch Exception e
(print e)))
(try (+ 2 2)
(finally
(print "hello")))
(try (+ 2 2)
(catch Exception e "hello")
(catch valueError e (+ 10 10)))
(try (+ 2 2)
(catch Exception e "caught the exception")
(finally (+ 10 10)))
(try (throw ValueError "my exception")
(catch ValueError e (print e))
(catch Exception e (print "caught exception"))
(finally (print "hello"))
(finally (print "goodbye")))
(try (+ 2 2)
(catch ValueError e (print e))
(finally (print "hello"))
(finally (print "goodbye")))
(try (throw Exception "my exception")
(catch ValueError e (print e))
(catch Exception e (print "caught exception"))
(finally (print "hello"))
(finally (print "goodbye")))
(print "-----------------------Binding forms")
(let* [x 1 y 2]
(+ x y))
;; -------------Borked stuff--------------
;; stuff not quite right.
;; NS both of them resolve to the name string, although one is supposed
;; to be the actual namespace.
*current-ns*
*ns*
;; (dir *ns*) ;; works.
;; (.items *ns* ;; doesn't work object bit is missing.
;; maps just don't work yet really. This does, but not much else.
(def y {:foo "bar"})
;; vectors, lists, sets, Make sure they work right.
;; try catch finally throw, loop & recur
;; tail recursion.