<< Back to previous view

[CLJS-724] "range" values are sometimes behaving unexpectedly Created: 10/Dec/13  Updated: 11/Dec/13  Resolved: 11/Dec/13

Status: Closed
Project: ClojureScript
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Michael Bradley, Jr. Assignee: Unassigned
Resolution: Completed Votes: 0
Labels: None
Environment:

browsers, rhino



 Description   

The lazy sequences returned by "range" are, in some situations, producing unexpected results as elements of larger computations.

Example:

(defn range-print [rng]
  (let [fst (first rng)
        rst (rest rng)]
    (when fst
      (.log js/console "first: " (clj->js fst))
      (.log js/console "rest: " (clj->js rst))
      (range-print rst))))

(range-print (range 3))

(range-print (map identity (range 3)))

(comment

  (range-print (range 3))

  ;; In my browser's console, the output of the above expression looks as
  ;; follows. Note the UNexpected "first" at the end.

  first:  0
  rest:  [1, 2]
  first:  1
  rest:  [2]
  first:  2
  rest:  []
  first:  3
  rest:  []

  ;; --------------------------------------------------------------------------

  (range-print (map identity (range 3)))

  ;; The above expression generates the output I expect.

  first:  0
  rest:  [1, 2]
  first:  1
  rest:  [2]
  first:  2
  rest:  []

  )


 Comments   
Comment by David Nolen [ 11/Dec/13 10:43 AM ]

fixed, https://github.com/clojure/clojurescript/commit/69f3a390df4a954d49077bfd67200aac18d8cd99

Generated at Mon Sep 15 04:52:37 CDT 2014 using JIRA 4.4#649-r158309.