On Jul 19, 12:53 pm, Richard Newman <[email protected]> wrote:
> > * Can the body of the db-push function be simplified?
>
> I think so. Untested:
>
> (defn db-push
> ([key val] (db-push key val *default-db*))
> ([key val db]
> (swap! db assoc key (cons val (db key))))))
If I add an @ it runs:
(defn db-push
([key val] (db-push key val *default-db*))
([key val db]
(swap! db assoc key (cons val (@db key)))))
But I think it's broken in the face of concurrency, as I capture the
value of @db at the time of the call to the function swap!
Actually using an ' instead of the @ seems to work:
(defn db-push
([key val] (db-push key val *default-db*))
([key val db]
(swap! db assoc key (cons val ('db key)))))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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
-~----------~----~----~----~------~----~------~--~---