cbc2eed900
defclass now has a new syntax: (defclass Name [BaseList] [property value property value] ;; optional (defn method [self] self.property)) Anything after the optional property list (which will be translated to a setv within the class context) will be added to the class body. This allows one to have side effects and complex expressions within the class definition. As a side effect, defining methods is much more friendly now! Closes #850. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
42 lines
919 B
Hy
42 lines
919 B
Hy
(defclass WithTest [object]
|
|
(defn --init-- [self val]
|
|
(setv self.val val)
|
|
None)
|
|
|
|
(defn --enter-- [self]
|
|
self.val)
|
|
|
|
(defn --exit-- [self type value traceback]
|
|
(setv self.val None)))
|
|
|
|
(defn test-single-with []
|
|
"NATIVE: test a single with"
|
|
(with [[t (WithTest 1)]]
|
|
(assert (= t 1))))
|
|
|
|
(defn test-two-with []
|
|
"NATIVE: test two withs"
|
|
(with [[t1 (WithTest 1)]
|
|
[t2 (WithTest 2)]]
|
|
(assert (= t1 1))
|
|
(assert (= t2 2))))
|
|
|
|
(defn test-thrice-with []
|
|
"NATIVE: test three withs"
|
|
(with [[t1 (WithTest 1)]
|
|
[t2 (WithTest 2)]
|
|
[t3 (WithTest 3)]]
|
|
(assert (= t1 1))
|
|
(assert (= t2 2))
|
|
(assert (= t3 3))))
|
|
|
|
(defn test-quince-with []
|
|
"NATIVE: test four withs, one with no args"
|
|
(with [[t1 (WithTest 1)]
|
|
[t2 (WithTest 2)]
|
|
[t3 (WithTest 3)]
|
|
[(WithTest 4)]]
|
|
(assert (= t1 1))
|
|
(assert (= t2 2))
|
|
(assert (= t3 3))))
|