ClojureScript

Lazy seqs fails to close over local vars

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    master clojurescript, commit 9abeb143f6

Description

When executing following code

(loop [i 10
       v [0]
       v2 [0]]
  (if (pos? i)
    (let [j i
          x (map #(+ j %) v)]
      (recur (dec i) x (map #(+ j %) v2)))
    (concat v v2)))

Clojure produces

(55 55)
while Clojurescript produces
(10 55)

Forcing realization of lazy seqs produces correct output (55 55) on both environments.

(loop [i 10
       v [0]
       v2 [0]]
  (if (pos? i)
    (let [j i
          x (doall (map #(+ j %) v))]
      (recur (dec i) x (doall (map #(+ j %) v2))))
    (concat v v2)))

Activity

Hide
Michał Marczyk added a comment -

This is actually due to a bug in analyze-let whereby functions involved in init-exprs would not close over earlier bindings. The attached patch fixes this.

Show
Michał Marczyk added a comment - This is actually due to a bug in analyze-let whereby functions involved in init-exprs would not close over earlier bindings. The attached patch fixes this.
Hide
Michał Marczyk added a comment -

Incidentally, I wonder whether *loop-lets* is still an appropriate name for this Var...

Show
Michał Marczyk added a comment - Incidentally, I wonder whether *loop-lets* is still an appropriate name for this Var...
Hide
David Nolen added a comment -

Do you have a better name in mind?

Show
David Nolen added a comment - Do you have a better name in mind?
Hide
Jozef Wagner added a comment -

Thank you, you guys are great!

Show
Jozef Wagner added a comment - Thank you, you guys are great!

People

Vote (1)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: