Clojure

rand-nth throws on empty list

Details

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

Description

rand-nth throws when given an empty list.

Solution is to either call seq on parameter, or to supply nil as a not-found parameter in call to nth. Patch fir latter fix included.

Activity

Hide
Andy Fingerhut added a comment -

Changing Patch attribute to value "Code", since I've been told that is what it ought to be for a ticket with a patch ready for screening.

Show
Andy Fingerhut added a comment - Changing Patch attribute to value "Code", since I've been told that is what it ought to be for a ticket with a patch ready for screening.
Andy Fingerhut made changes -
Field Original Value New Value
Patch Fixed [ 10009 ] Code [ 10001 ]
Rich Hickey made changes -
Approval None [ 10008 ]
Rich Hickey made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]
Hide
Michael Nygard added a comment -

This is marked as "Completed," but the reported behavior still exists in 1.7.0. Was the fix rejected?

Show
Michael Nygard added a comment - This is marked as "Completed," but the reported behavior still exists in 1.7.0. Was the fix rejected?
Hide
Andy Fingerhut added a comment -

From looking at revision history, it seems that rand-nth has never been changed since it was added. Perhaps no fix was ever committed for it, maybe by accident.

Show
Andy Fingerhut added a comment - From looking at revision history, it seems that rand-nth has never been changed since it was added. Perhaps no fix was ever committed for it, maybe by accident.
Hide
Alex Miller added a comment -

Since I just happened to run across this and future finders... Rich closed this (should have been declined really) because this is working as designed. Returning a random nth element requires there to be at least one element. Returning nil would mean returning a value that is not part of the original collection, which violates the contract.

Perhaps we'll soon have a spec for this that checks #(not (empty? %)).

Show
Alex Miller added a comment - Since I just happened to run across this and future finders... Rich closed this (should have been declined really) because this is working as designed. Returning a random nth element requires there to be at least one element. Returning nil would mean returning a value that is not part of the original collection, which violates the contract. Perhaps we'll soon have a spec for this that checks #(not (empty? %)).

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: