diff --git a/hy/contrib/anaphoric.hy b/hy/contrib/anaphoric.hy index 5a6b236..5000cbf 100644 --- a/hy/contrib/anaphoric.hy +++ b/hy/contrib/anaphoric.hy @@ -84,18 +84,20 @@ (defmacro ap-first [predfn lst] "Yield the first element that passes `predfn`" - `(let [[n (gensym)]] - (ap-each ~lst (when ~predfn (setv n it) (break))) - n)) + (with-gensyms [n] + `(let [[~n None]] + (ap-each ~lst (when ~predfn (setv ~n it) (break))) + ~n))) (defmacro ap-last [predfn lst] "Yield the last element that passes `predfn`" - `(let [[n (gensym)]] - (ap-each ~lst (none? n) - (when ~predfn - (setv n it))) - n)) + (with-gensyms [n] + `(let [[~n None]] + (ap-each ~lst (none? ~n) + (when ~predfn + (setv ~n it))) + ~n))) (defmacro ap-reduce [form lst &optional [initial-value None]] diff --git a/tests/native_tests/contrib/anaphoric.hy b/tests/native_tests/contrib/anaphoric.hy index 3d67e82..50281fa 100644 --- a/tests/native_tests/contrib/anaphoric.hy +++ b/tests/native_tests/contrib/anaphoric.hy @@ -87,12 +87,14 @@ (defn test-ap-first [] "NATIVE: testing anaphoric first" (assert-equal (ap-first (> it 5) (range 10)) 6) - (assert-equal (ap-first (even? it) [1 2 3 4]) 2)) + (assert-equal (ap-first (even? it) [1 2 3 4]) 2) + (assert-equal (ap-first (> it 10) (range 10)) None)) (defn test-ap-last [] "NATIVE: testing anaphoric last" (assert-equal (ap-last (> it 5) (range 10)) 9) - (assert-equal (ap-last (even? it) [1 2 3 4]) 4)) + (assert-equal (ap-last (even? it) [1 2 3 4]) 4) + (assert-equal (ap-last (> it 10) (range 10)) None)) (defn test-ap-reduce [] "NATIVE: testing anaphoric reduce"