From b12c930444c325b1e321f6831b3372422feae38a Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sat, 21 Dec 2019 11:10:30 -0500 Subject: [PATCH] Allow non-constant `n` in `ap-dotimes` --- hy/extra/anaphoric.hy | 2 -- tests/native_tests/extra/anaphoric.hy | 8 +++++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/hy/extra/anaphoric.hy b/hy/extra/anaphoric.hy index d53e9fc..b32fbeb 100644 --- a/hy/extra/anaphoric.hy +++ b/hy/extra/anaphoric.hy @@ -66,8 +66,6 @@ (defmacro ap-dotimes [n &rest body] "Execute body for side effects `n' times, with it bound from 0 to n-1" - (unless (numeric? n) - (raise (TypeError (.format "{!r} is not a number" n)))) `(ap-each (range ~n) ~@body)) diff --git a/tests/native_tests/extra/anaphoric.hy b/tests/native_tests/extra/anaphoric.hy index d99779f..8191f2c 100644 --- a/tests/native_tests/extra/anaphoric.hy +++ b/tests/native_tests/extra/anaphoric.hy @@ -47,7 +47,13 @@ (assert (= (do (setv n []) (ap-dotimes 3 (.append n 3)) n) [3 3 3])) (assert (= (do (setv n []) (ap-dotimes 3 (.append n it)) n) - [0 1 2]))) + [0 1 2])) + + ; https://github.com/hylang/hy/issues/1853 + (setv n 5) + (setv x "") + (ap-dotimes n (+= x ".")) + (assert (= x "....."))) (defn test-ap-first [] (assert (= (ap-first (> it 5) (range 10)) 6))