Skip to content

Commit 77db40c

Browse files
committed
string representations for Range
1 parent 0563346 commit 77db40c

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

pixie/stdlib.pxi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,13 @@ For more information, see http://clojure.org/special_forms#binding-forms"}
17681768
(and (< step 0) (> start stop)))
17691769
(cons start (lazy-seq* #(range (+ start step) stop step))))))
17701770

1771+
(extend -str Range
1772+
(fn [v]
1773+
(-str (seq v))))
1774+
(extend -repr Range
1775+
(fn [v]
1776+
(-repr (seq v))))
1777+
17711778
(defn range
17721779
{:doc "Returns a range of numbers."
17731780
:examples [["(seq (range 3))" nil (0 1 2)]

tests/pixie/tests/test-stdlib.pxi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
(t/assert= (str {:a 1}) "{:a 1}")
3737
(t/assert= (str (type 3)) "<type pixie.stdlib.Integer>")
3838
(t/assert= (str [1 {:a 1} "hey"]) "[1 {:a 1} hey]")
39-
(t/assert= (seq (map identity "iterable")) '(\i \t \e \r \a \b \l \e)))
39+
(t/assert= (seq (map identity "iterable")) '(\i \t \e \r \a \b \l \e))
40+
(t/assert= (str (range 3)) "(0 1 2)"))
4041

4142
(t/deftest test-repr
4243
(t/assert= (-repr nil) "nil")
@@ -58,7 +59,8 @@
5859
(t/assert= (-repr {:a 1}) "{:a 1}")
5960
(t/assert= (-repr (type 3)) "pixie.stdlib.Integer")
6061

61-
(t/assert= (-repr [1 {:a 1} "hey"]) "[1 {:a 1} \"hey\"]"))
62+
(t/assert= (-repr [1 {:a 1} "hey"]) "[1 {:a 1} \"hey\"]")
63+
(t/assert= (-repr (range 3)) "(0 1 2)"))
6264

6365
(t/deftest test-nth
6466
;; works if the index is found

0 commit comments

Comments
 (0)