You may want to use some delays to prevent evaluation of untaken branches:

user=> (iff true :else (println 1) :then (println 3))
3
1
nil
user=>


On Sat, Dec 8, 2012 at 3:02 PM, Thomas Goossens
<cont...@thomasgoossens.be> wrote:
> One of the issues i had and still have with the if function  is that
> because it has ordered arguments, makes things more complex.
>
> For small functions this is no so much of a problem.
> (if test 1 0)
>
> But when things get larger,  that extra complexity of order without explicit
> information can get significant, I believe
>
> So I wanted (this would be officially my first macro ever!) something that
> behaved as follows:
>
> (if test
>  :then true
>  :else false)
>
> (if test
>  :else false
>  :then true)
>
> Which is what I eventually did:
>
> (defmacro iff
>   [test & body]
>   (let [args (apply hash-map body)]
>       `(if ~test (:then ~args) (:else ~args))))
>
> Any thoughts, improvements on my macro? (Also I'm not quite sure how to
> document my macro. So any advice on that is appreciated :)
>
>
>
> --
> 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



-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]

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