Johann Hibschman wrote:
Does anyone have style suggestions for distinguishing the states from
the refs to mutable data?
Let's say I'm manipulating a cell in a lattice, or doing dynamic
programming, or something. In any case, I have a cell.
;; Current convention: use "cell-" as the type of the state of a
"cell".
(defstruct cell- :location :data)
(defn make-cell [location data]
(ref (struct-map cell- :location location :data data))
(defn print-cell- [cell-state]
(prn cell-state))
(defn print-cell [cell]
(print-cell- @cell))
The details don't matter that much, but what would people name these
arguments? Is the "cell-" convention good? I'd use something like "cell
%" if I were in scheme, but that's not legal in Clojure. What should I
name function arguments to distinguish the ones that take the refs
from the ones that take the states?
Clearly, I can come up with something that keeps me happy, but I was
wondering if the community's evolved a standard or has an opinion.
I'm a stranger here myself, but from what I've seen, the trailing hyphen
convention is already commonly used to mean something is private to a
namespace, or is a function that defines such private somethings.
This may be a dumb question, but why bother defining separate functions
to define the refs? It seems like print-cell should actually accept a
cell. It's straightforward to deref in the client code:
(print-cell @cell)
If it gives you frissons, you can spell it like this:
(print-cell@ cell)
--
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