Clojure

`reductions should respect `reduced

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code
  • Approval:
    Triaged

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))

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.

Activity

Hide
Brandon Bloom added a comment -

Attaching patch

Show
Brandon Bloom added a comment - Attaching patch
Hide
Satshabad Khalsa added a comment -

Would love some progress on this!

Show
Satshabad Khalsa added a comment - Would love some progress on this!
Hide
Andy Fingerhut added a comment -

It isn't guaranteed to help, but it can't hurt to vote on the ticket, and encourage anyone else you know who wants this fixed to vote on it.

Show
Andy Fingerhut added a comment - It isn't guaranteed to help, but it can't hurt to vote on the ticket, and encourage anyone else you know who wants this fixed to vote on it.

People

Vote (3)
Watch (2)

Dates

  • Created:
    Updated: