> * Is "function overloading" the idiomatic way to implement default
> params in clojure?
Typically, I think so. You could also use multimethods, but that might
be unnecessary flexibility.
Another approach is to emulate keyword arguments:
(defn foo [x y & args]
(let [{:keys [baz bar]} (apply hash-map args)]
...))
(foo 5 6 :baz 9 :bar noo)
> * I'm using an atom to store the database. Could I use a var instead?
I probably wouldn't. You could use a ref.
> * 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 it's a ref, the analogue would be
(defn db-push
([key val] (db-push key val *default-db*))
([key val db]
(dosync
(alter db assoc key (cons val (db key))))))
or document that db-push must be called within a transaction, and
remove the dosync. (This allows multiple pushes within a single
transaction.)
-R
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---