Allow non-constant `n` in `ap-dotimes`

This commit is contained in:
Kodi Arfer 2019-12-21 11:10:30 -05:00
parent c2a3f61ab2
commit b12c930444
2 changed files with 7 additions and 3 deletions

View File

@ -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))

View File

@ -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))