Count is going to be slow for seqs or cons's, but I think a generalized
function could be implemented via protocol, falling back to seq.  Things
that extend
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Counted.java
are
going to have a fast 'count' method.

On Thu, Oct 1, 2015 at 6:40 PM Nathan Davis <nda...@positronic-solutions.com>
wrote:

> On Thursday, October 1, 2015 at 2:31:46 PM UTC-5, Dave Tenny wrote:
>>
>> So I understand that 'seq' is the idiomatic way to see if a
>> collection/sequence is empty.
>>
>>
> I'm not sure where you got this from.  I personally use empty? to check
> whether a collection is empty.  It is true that (not (empty c)) is not
> encouraged.  I believe the main rationale for this this is that (empty c)
> is (not (seq c)), so (not (empty c)) is (not (not (seq c)).
>
>
>> Logically I'm looking for an O(1) predicate with which I can determine if
>> a seq/collection is empty, and a well behaved
>> one that is idempotent and side effect free (for general performance
>> reasons).
>>
>
> I believe all the implementations of seq in Clojure core are O(1),
> although some (most?) allocate objects.  I'm not sure if it's explicitly
> spelled out anywhere, but I would consider it a bug it was anything other
> than O(1) (or perhaps O(log n) at most).
>
> In what ways is the current implementation of empty not well behaved and
> idempotent?
>
> With regards to side effects, if you can find a completely generic,
> side-effect-free way of determining whether a lazy sequence is empty
> without potentially realizing its head, please let the Clojure community
> know!
>
> I'm not saying having an explicit 'empty' method is a bad idea, but I'm
> not sure the current situation is as bad as you think.
>
>
> Nathan Davis
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to