Fix anaphoric macro ap-if.

This commit is contained in:
Ewald Grusk 2015-06-17 00:11:55 +02:00
parent ba03d2351c
commit b2a72e2f10
2 changed files with 10 additions and 5 deletions

View File

@ -25,8 +25,9 @@
;;; These macros make writing functional programs more concise
(defmacro ap-if (test-form &rest args)
`(let [it ~test-form] (if it ~@args)))
(defmacro ap-if [test-form then-form &optional else-form]
`(let [it ~test-form]
(if it ~then-form ~else-form)))
(defmacro ap-each [lst &rest body]

View File

@ -18,10 +18,11 @@
;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;; DEALINGS IN THE SOFTWARE.
;;;; some simple helpers
(import [hy.errors [HyMacroExpansionError]])
(require hy.contrib.anaphoric)
;;;; some simple helpers
(defn assert-true [x]
(assert (= True x)))
@ -35,7 +36,10 @@
(defn test-ap-if []
"NATIVE: testing anaphoric if"
(ap-if true (assert-true it))
(ap-if false true (assert-false it)))
(ap-if false true (assert-false it))
(try (macroexpand '(ap-if true))
(except [HyMacroExpansionError] true)
(else (assert false))))
(defn test-ap-each []
"NATIVE: testing anaphoric each"