1
0
mirror of https://github.com/janet-lang/janet synced 2025-06-21 07:54:12 +00:00

Make range variadic.

This commit is contained in:
Calvin Rose 2018-07-11 11:57:17 -04:00
parent a1bdc3a023
commit 55ff1ee7e8

View File

@ -547,10 +547,19 @@
(defn range (defn range
"Create an array of values [0, n)." "Create an array of values [0, n)."
[n] [& args]
(def arr (array.new n)) (case (length args)
(loop [i :range [0 n]] (put arr i i)) 1 (do
arr) (def [n] args)
(def arr (array.new n))
(loop [i :range [0 n]] (put arr i i))
arr)
2 (do
(def [n m] args)
(def arr (array.new n))
(loop [i :range [n m]] (put arr (- i n) i))
arr)
(error "expected 1 to 2 arguments to range")))
(defn find-index (defn find-index
"Find the index of indexed type for which pred is true. Returns nil if not found." "Find the index of indexed type for which pred is true. Returns nil if not found."