Clojure

Should "some" be using "seq?" rather than "seq" ?

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: Release 1.2
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Mac OS X Java 6

Description

Very minor, but noticed while browsing that "some" is defined as:

(defn some
...
[pred coll]
(when (seq coll)
(or (pred (first coll)) (recur pred (next coll)))))

The "(seq coll)" call will potentially generate an unused seq each time.

Activity

Fogus made changes -
Field Original Value New Value
Assignee Michel Fogus [ fogus ]
Hide
Fogus added a comment -

The `seq` function is the idiomatic way to ask the question "does this collection have something in it?" and is the correct approach in the case of `some`. If we were to use `seq?` then we would be asking an entirely different question: "does this collection implement the ISeq interface". In the case of using `seq?`, `some` would no longer work against the seq abstraction. It's tempting to look at the name `seq` and `seq?` and assume that they mean similar things. The type-based predicates are tricky.

Show
Fogus added a comment - The `seq` function is the idiomatic way to ask the question "does this collection have something in it?" and is the correct approach in the case of `some`. If we were to use `seq?` then we would be asking an entirely different question: "does this collection implement the ISeq interface". In the case of using `seq?`, `some` would no longer work against the seq abstraction. It's tempting to look at the name `seq` and `seq?` and assume that they mean similar things. The type-based predicates are tricky.
Fogus made changes -
Status Open [ 1 ] Closed [ 6 ]
Assignee Michel Fogus [ fogus ]
Resolution Declined [ 2 ]
Hide
Matthew Phillips added a comment -

Thanks for the informative comment Michael. I was just watching Rich's talk on seq's, and remembered making this noob bug report: sorry!

Show
Matthew Phillips added a comment - Thanks for the informative comment Michael. I was just watching Rich's talk on seq's, and remembered making this noob bug report: sorry!

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: