Clojure

`reductions should respect `reduced

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Critical Critical
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: Release 1.7
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Screened

Description

This returns 16:

(reduce (fn [acc x]
          (let [x' (* x x)]
            (if (> x' 10)
              (reduced x')
              x')))
        (range))

But replacing reduce with reductions will never terminate:

(reductions (fn [acc x]
              (let [x' (* x x)]
                (if (> x' 10)
                  (reduced x')
                  x')))
            (range))

Cause: reductions ignores clojure.lang.Reduced, it never tests for reduced?

Patch: CLJ-1181-v002.patch

Screened by: Alex Miller

  1. CLJ-1181-v001.patch
    16/Mar/13 6:10 PM
    1.0 kB
    Brandon Bloom
  2. CLJ-1181-v002.patch
    14/Jun/14 4:10 PM
    2 kB
    Brandon Bloom

Activity

Brandon Bloom made changes -
Field Original Value New Value
Attachment CLJ-1181-v001.patch [ 11921 ]
Andy Fingerhut made changes -
Patch Code [ 10001 ]
Alex Miller made changes -
Approval Triaged [ 10120 ]
Issue Type Enhancement [ 4 ] Defect [ 1 ]
Alex Miller made changes -
Priority Minor [ 4 ] Critical [ 2 ]
Rich Hickey made changes -
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Rich Hickey made changes -
Fix Version/s Release 1.7 [ 10250 ]
Alex Miller made changes -
Approval Vetted [ 10003 ] Incomplete [ 10006 ]
Brandon Bloom made changes -
Attachment CLJ-1181-v002.patch [ 13079 ]
Brandon Bloom made changes -
Patch Code [ 10001 ] Code and Test [ 10002 ]
Alex Miller made changes -
Approval Incomplete [ 10006 ] Vetted [ 10003 ]
Alex Miller made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Description This returns 16:

{code}
(reduce (fn [acc x]
          (let [x' (* x x)]
            (if (> x' 10)
              (reduced x')
              x')))
        (range))
{code}

But replacing `reduce with `reductions will never terminate:

{code}
(reductions (fn [acc x]
              (let [x' (* x x)]
                (if (> x' 10)
                  (reduced x')
                  x')))
            (range))
{code}

This is because `reductions ignores 'clojure.lang.Reduced, it never tests for `reduced?

I know that I only just discovered the `reduced, function, but `reductions is a big part of my debugging process, so it's unfortunate that they don't work together.
This returns 16:

{code}
(reduce (fn [acc x]
          (let [x' (* x x)]
            (if (> x' 10)
              (reduced x')
              x')))
        (range))
{code}

But replacing `reduce with `reductions will never terminate:

{code}
(reductions (fn [acc x]
              (let [x' (* x x)]
                (if (> x' 10)
                  (reduced x')
                  x')))
            (range))
{code}

*Cause:* {reductions} ignores {clojure.lang.Reduced}, it never tests for {reduced}?

*Patch:* CLJ-1181-v002.patch

*Screened by:* Alex Miller
Alex Miller made changes -
Description This returns 16:

{code}
(reduce (fn [acc x]
          (let [x' (* x x)]
            (if (> x' 10)
              (reduced x')
              x')))
        (range))
{code}

But replacing `reduce with `reductions will never terminate:

{code}
(reductions (fn [acc x]
              (let [x' (* x x)]
                (if (> x' 10)
                  (reduced x')
                  x')))
            (range))
{code}

*Cause:* {reductions} ignores {clojure.lang.Reduced}, it never tests for {reduced}?

*Patch:* CLJ-1181-v002.patch

*Screened by:* Alex Miller
This returns 16:

{code}
(reduce (fn [acc x]
          (let [x' (* x x)]
            (if (> x' 10)
              (reduced x')
              x')))
        (range))
{code}

But replacing {{reduce}} with {{reductions}} will never terminate:

{code}
(reductions (fn [acc x]
              (let [x' (* x x)]
                (if (> x' 10)
                  (reduced x')
                  x')))
            (range))
{code}

*Cause:* {{reductions}} ignores {{clojure.lang.Reduced}}, it never tests for {{reduced}}?

*Patch:* CLJ-1181-v002.patch

*Screened by:* Alex Miller

People

Vote (4)
Watch (2)

Dates

  • Created:
    Updated: