2013-04-28 17:14:22 +02:00
|
|
|
(defn foodec [func]
|
|
|
|
(lambda [] (+ 1 1)))
|
|
|
|
|
|
|
|
|
|
|
|
(with-decorator foodec
|
|
|
|
(defn tfunction []
|
|
|
|
(* 2 2)))
|
|
|
|
|
|
|
|
|
2014-11-14 21:21:16 +01:00
|
|
|
(defn bardec [cls]
|
2014-11-15 13:47:55 +01:00
|
|
|
(setv cls.my_attr 123)
|
|
|
|
cls)
|
2014-11-14 21:21:16 +01:00
|
|
|
|
|
|
|
(with-decorator bardec
|
|
|
|
(defclass cls []
|
2015-08-04 16:43:07 +02:00
|
|
|
[my_attr 456]))
|
2014-11-14 21:21:16 +01:00
|
|
|
|
2015-01-14 20:42:02 +01:00
|
|
|
(defn test-decorator-clobbing []
|
|
|
|
"NATIVE: Tests whether nested decorators work"
|
|
|
|
(do
|
|
|
|
(defn dec1 [f] (defn k [] (+ (f) 1)))
|
|
|
|
(defn dec2 [f] (defn k [] (+ (f) 2)))
|
|
|
|
(with-decorator dec1
|
|
|
|
(with-decorator dec2
|
|
|
|
(defn f [] 1)))
|
|
|
|
(assert (= (f) 4))))
|
2014-11-14 21:21:16 +01:00
|
|
|
|
2013-04-28 17:14:22 +02:00
|
|
|
(defn test-decorators []
|
|
|
|
"NATIVE: test decorators."
|
2014-11-14 21:21:16 +01:00
|
|
|
(assert (= (tfunction) 2))
|
|
|
|
(assert (= cls.my_attr 123)))
|