I think this is pretty useful, but I'm a noob and don't know better :)
I found myself trying to use atoms and refs to start with rather than
taking a functional approach, maybe something like this is good in the
standard lib to emphasize a functional approach? Or maybe it exists
and I don't know it????
(defmacro conj-when [pred new & coll]
`(let [test# ~pred]
(if test#
(conj [EMAIL PROTECTED] ~new)
[EMAIL PROTECTED])))
and an example ...
(defn- syncPacket [r]
(let [state (r :state)]
(conj-when (= state :WINNER) { :WINNER (r :winBall) }
(conj-when (or (= state :CONGRATS) (= state
:START)) {:COUNTDOWN
(r :countDown)}
{
:CUR_SEC (r :sec)
:PRIZE (r :prize)
:JACKPOT (r :jackpot)
:BUY_INS (count @(r :cards))
:STATE (subs (str state) 1)
:MESSAGE (r :message)
}))))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---