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



On 09/01/2011, at 10:36 AM, Ken Wesson wrote:

> On Sat, Jan 8, 2011 at 7:25 PM, Andreas Kostler
> <andreas.koestler.le...@gmail.com> wrote:
>> Ken,
>> Thanks for your reply. Is that about what you mean?
>> 
>> (defmacro literal? [form]
>>  (list 'if `(not (list? ~form)) true false))
> 
> Sort of, but that isn't quite going to work. It will expand to
> 
> (if (clojure.core/not (clojure.core/list? <the-form>)) true false)
> 
> That's not especially efficient; you can dispense with the if entirely
> and just use
> 
> `(not (list? ~form))
> 
> and get the same results. But the results also won't be what you're
> hoping for. Put in
> 
> (literal? (+ 2 3))
> 
> and you'll get true! That's because it will expand to
> 
> (not (list? (+ 2 3)))
> 
> which will evaluate to (not (list? 5)) and then (not false) and then
> true. 5 is not a list.
> 
> The problem is that the list? test is happening at run time, not
> macroexpansion time. You'd need
> 
> (defmacro literal? [form]
>  (not (list? form)))
> 
> which will simply evaluate to true or false depending.
> 
> (literal? (+ 2 3))
> 
> will now expand to false, and that will evaluate to false.
> 
> I'm not sure what use this is, though. I suppose you want to know if
> an argument to some more complex macro is literal or not, in which
> case (not (list? arg)) (OUTSIDE of your syntax-quotes, or unquoted)
> will do nicely, depending on your requirements.
> 
> But do you want [1 2] and [(- 3 2) (+ 1 1)] to both count as literal,
> or only the former? What about [(count my-seq) (reduce + (map
> parse-int (line-seq rdr)))]? Do you want (quote (1 2 3)) to count as
> literal?
> 
> -- 
> 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

--
 “There is a strong correlation between being smart and being a nerd, and an 
even stronger inverse correlation between being a nerd and being popular”
(Paul Graham)
-- 
**********************************************************
Andreas Koestler, Software Engineer
Leica Geosystems Pty Ltd
270 Gladstone Road, Dutton Park QLD 4102
Main: +61 7 3891 9772     Direct: +61 7 3117 8808
Fax: +61 7 3891 9336
Email: andreas.koest...@leica-geosystems.com

************www.leica-geosystems.com*************

when it has to be right, Leica Geosystems

Please  consider the environment before printing this email.





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