diff --git a/hy/contrib/anaphoric.hy b/hy/contrib/anaphoric.hy index 9129bd4..aaee36b 100644 --- a/hy/contrib/anaphoric.hy +++ b/hy/contrib/anaphoric.hy @@ -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] diff --git a/tests/native_tests/contrib/anaphoric.hy b/tests/native_tests/contrib/anaphoric.hy index 9e0ddd9..69caac2 100644 --- a/tests/native_tests/contrib/anaphoric.hy +++ b/tests/native_tests/contrib/anaphoric.hy @@ -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"