37 lines
766 B
Hy
37 lines
766 B
Hy
(defmacro rev [&rest body]
|
|
"Execute the `body` statements in reverse"
|
|
(quasiquote (do (unquote-splice (list (reversed body))))))
|
|
|
|
|
|
(defn test-rev-macro []
|
|
"NATIVE: test stararged native macros"
|
|
(setv x [])
|
|
(rev (.append x 1) (.append x 2) (.append x 3))
|
|
(assert (= x [3 2 1])))
|
|
|
|
|
|
; Macros returning constants
|
|
|
|
(defmacro an-int [] 42)
|
|
(assert (= (an-int) 42))
|
|
|
|
(defmacro a-true [] True)
|
|
(assert (= (a-true) True))
|
|
(defmacro a-false [] False)
|
|
(assert (= (a-false) False))
|
|
|
|
(defmacro a-float [] 42.)
|
|
(assert (= (a-float) 42.))
|
|
|
|
(defmacro a-complex [] 42j)
|
|
(assert (= (a-complex) 42j))
|
|
|
|
(defmacro a-string [] "foo")
|
|
(assert (= (a-string) "foo"))
|
|
|
|
(defmacro a-list [] [1 2])
|
|
(assert (= (a-list) [1 2]))
|
|
|
|
(defmacro a-dict [] {1 2})
|
|
(assert (= (a-dict) {1 2}))
|