>> Basically, I want the clojure equivalent of a clisp atom.
>> In clisp, atom is true for everything that is not a cons cell.
>> The closest match I found is creating a macro that returns true for 
>> everything that is not a list:
>> clisp:
>> 
>> (atom 1) => true
>> (atom '(1 2 3)) => false
>> 
>> I hope that makes things clearer :)
>> Andreas
> 
> Sounds like you really just want
> 
> (defn atom? [x]
>  (not
>    (or
>      (instance? java.util.Collection x)
>      (instance? java.util.Map x))))
> 
> which returns true for integers, strings, and pretty much any other
> objects except lists, seqs, vectors, maps, sets, and the like (and
> their mutable java.util counterparts).

Additional corner cases to consider:

* nil
* arrays
* poorly-designed Java classes that are clearly collection-like but don't 
implement collection interfaces.

I needed to make a decision for all these cases in order to implement 
clojure.data/diff. The function clojure.data/equality-partition can be used to 
check for atomness, but note the docstring: implementation detail and subject 
to change.

What else can you tell us about your use case? 

Stu

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