Allow non-constant n
in ap-dotimes
This commit is contained in:
parent
c2a3f61ab2
commit
b12c930444
@ -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))
|
||||
|
||||
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user