ClojureScript

Sequence and Eduction produce infinite loop in transducer that appends to the reduction

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: 1.9.655
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test

Description

Example: a transducer that appends :foo to the result of the reduction:

(defn xf []
  (fn [rf]
    (fn
      ([] (rf))
      ([result] (rf result :foo))
      ([result input]
       (rf result input)))))

(sequence (xf) [1 2 3])

In Clojure, the above code yields

'(1 2 3 :foo)
. In ClojureScript, it results in an infinite loop. The same happens with `eduction`.
However,
(into [] (xf) [1 2 3])
doesn't produce an error.

Activity

Hide
António Nuno Monteiro added a comment -

I'm looking into fixing this one.

Show
António Nuno Monteiro added a comment - I'm looking into fixing this one.
Hide
António Nuno Monteiro added a comment -

The implementation of transducers in ClojureScript tracked an old counterpart in
the Clojure codebase. This patch addresses the change introduced in the
following commit to Clojure, which replaced `LazyTransformer` with
`TransformerIterator`, effectively making the transducer behavior akin to the
one in Clojure.

https://github.com/clojure/clojure/commit/c47e1bbcfa227723df28d1c9e0a6df2bcb0fecc1

Attached patch with fix and test.

Show
António Nuno Monteiro added a comment - The implementation of transducers in ClojureScript tracked an old counterpart in the Clojure codebase. This patch addresses the change introduced in the following commit to Clojure, which replaced `LazyTransformer` with `TransformerIterator`, effectively making the transducer behavior akin to the one in Clojure. https://github.com/clojure/clojure/commit/c47e1bbcfa227723df28d1c9e0a6df2bcb0fecc1 Attached patch with fix and test.
Hide
Mike Fikes added a comment -

See regression in CLJS-2258.

Show
Mike Fikes added a comment - See regression in CLJS-2258.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: