diff --git a/hy/contrib/anaphoric.hy b/hy/contrib/anaphoric.hy index 2f37b47..5a6b236 100644 --- a/hy/contrib/anaphoric.hy +++ b/hy/contrib/anaphoric.hy @@ -46,9 +46,10 @@ (defmacro ap-map [form lst] "Yield elements evaluated in the form for each element in the list." - `(let [[f (lambda [it] ~form)]] - (for [v ~lst] - (yield (f v))))) + (let [[v (gensym 'v)] [f (gensym 'f)]] + `(let [[~f (lambda [it] ~form)]] + (for [~v ~lst] + (yield (~f ~v)))))) (defmacro ap-map-when [predfn rep lst] diff --git a/tests/native_tests/contrib/anaphoric.hy b/tests/native_tests/contrib/anaphoric.hy index 791b24c..3d67e82 100644 --- a/tests/native_tests/contrib/anaphoric.hy +++ b/tests/native_tests/contrib/anaphoric.hy @@ -54,7 +54,9 @@ (assert-equal (list (ap-map (* it 3) [1 2 3])) [3 6 9]) (assert-equal (list (ap-map (* it 3) [])) - [])) + []) + (assert-equal (let [[v 1] [f 1]] (list (ap-map (it v f) [(fn [a b] (+ a b))]))) + [2])) (defn test-ap-map-when [] "NATIVE: testing anaphoric map-when"