Uploaded image for project: 'Clojure'
  1. CLJ-1572

into does not work with IReduceInit

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: Release 1.7
    • Fix versions: Release 1.7
    • Labels:
    • Approval:
      Ok
    • Patch:
      Code and Test

      Description

      This should work:

      (into []
        (reify clojure.lang.IReduceInit
          (reduce [_ f start]
            (reduce f start (range 10)))))
      IllegalArgumentException Don't know how to create ISeq from: user$eval5$reify__6
      	clojure.lang.RT.seqFrom (RT.java:506)
      	clojure.lang.RT.seq (RT.java:487)
      	clojure.core/seq--seq--4091 (core.clj:135)
      	clojure.core.protocols/seq-reduce (protocols.clj:30)
      	clojure.core.protocols/fn--6422 (protocols.clj:42)
      	clojure.core.protocols/fn--6369/f--6255--auto----G--6364--6382 (protocols.clj:13)
      	clojure.core/reduce (core.clj:6469)
      	clojure.core/into (core.clj:6550)
      

      Cause: CollReduce only supports IReduce, not IReduceInit so when reduce calls into it, it falls back to trying to obtain a seq representation which fails.

      Proposed: Extend CollReduce to IReduceInit and in the non-init arity, cast to IReduce. Also, now that CollReduce supports both IReduceInit and Iterable, a coll that implements both makes the path through CollReduce nondeterministic. transduce does an explicit check that prefers IReduceInit - the patch copies that approach to reduce as well.

      Another consequence of this change is that since PersistentVector implements IReduce but throws on the non-init path, there are some test breakages. To address this, CLJ-1619 Closed (which implements the non-init reduce) must be applied first.

      Patch: clj-1572-4.patch
      Depends on: CLJ-1619 Closed being applied first

        Attachments

        1. clj-1572.patch
          0.8 kB
        2. clj-1572-2.patch
          2 kB
        3. clj-1572-3.patch
          2 kB
        4. clj-1572-4.patch
          2 kB
        5. CLJ-1572-alternative-POC.patch
          5 kB

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alexmiller Alex Miller
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: