merge branch 'fix-anaphoric-if'

This commit is contained in:
Zack M. Davis 2016-02-28 19:35:07 -08:00
commit 4cee7b1e10
2 changed files with 10 additions and 5 deletions

View File

@ -25,8 +25,9 @@
;;; These macros make writing functional programs more concise ;;; These macros make writing functional programs more concise
(defmacro ap-if (test-form &rest args) (defmacro ap-if [test-form then-form &optional else-form]
`(let [it ~test-form] (if it ~@args))) `(let [it ~test-form]
(if it ~then-form ~else-form)))
(defmacro ap-each [lst &rest body] (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 ;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;; DEALINGS IN THE SOFTWARE. ;; DEALINGS IN THE SOFTWARE.
;;;; some simple helpers (import [hy.errors [HyMacroExpansionError]])
(require hy.contrib.anaphoric) (require hy.contrib.anaphoric)
;;;; some simple helpers
(defn assert-true [x] (defn assert-true [x]
(assert (= True x))) (assert (= True x)))
@ -35,7 +36,10 @@
(defn test-ap-if [] (defn test-ap-if []
"NATIVE: testing anaphoric if" "NATIVE: testing anaphoric if"
(ap-if true (assert-true it)) (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 [] (defn test-ap-each []
"NATIVE: testing anaphoric each" "NATIVE: testing anaphoric each"