On Sun, Nov 14, 2010 at 9:36 PM, Eric Kobrin <erl...@gmail.com> wrote:

> This brought to mind the general case of detecting emptiness. The
> current practice of using `seq` to check for non-emptiness wastes
> resources.


It depends: in many cases you need to call seq anyway in the non-empty
branch so seq+if-let is both expressive and efficient.

However from time to time you really need to check for emptiness quickly.
(zero? (count x)) is one way, (.isEmpty ^java.util.Collection x) is another.

This limits the use of nice abstractions like `reduce` in
> performance critical environments where a sentinel could be used. Not
> everyone will be able to use a sentinel value to solve their
> particular problem. What can be done to make `empty` faster?
>

However if your [] is really a sentinel, what about creating a real sentinel
with (Object.) or (gensym) and checking it with identical?

hth,

Christophe

-- 
Professional: http://cgrand.net/ (fr)
On Clojure: http://clj-me.cgrand.net/ (en)

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

Reply via email to