<< Back to previous view

[CLJ-692] Should "some" be using "seq?" rather than "seq" ? Created: 16/Dec/10  Updated: 08/Jul/11  Resolved: 27/Dec/10

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.2
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Matthew Phillips Assignee: Unassigned
Resolution: Declined Votes: 0
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.



 Comments   
Comment by Fogus [ 27/Dec/10 7:57 AM ]

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.

Comment by Matthew Phillips [ 08/Jul/11 3:28 AM ]

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

Generated at Tue Oct 21 12:06:37 CDT 2014 using JIRA 4.4#649-r158309.