Naming Conventions for Functions that Modify State

37 views
Skip to first unread message

Kevin Albrecht

unread,
Feb 12, 2009, 1:04:30 AM2/12/09
to Clojure
In Scheme, the common scheme used to name functions with side effects
is to append an exclamation mark to the function name. Obviously, the
types of ways in which Clojure abstracts state modifications are more
complicated and complete than Scheme, so maybe a function naming
scheme for Clojure functions could be useful. Is there a naming
scheme already being used out there or proposals for one? Here are a
few examples of idioms I have seen that could maybe use a naming
scheme:

1. Function that has a side effect:

(defn alpha [msg]
(println msg))

2. Function that performs a transaction (and therefore has a side
effect):

(defn beta []
(dosync (ref-set foo 10)))

3. Function that needs to be in a transaction:

(defn gamma []
(ref-set bar 42))

--Kevin Albrecht

Kevin Albrecht

unread,
Feb 12, 2009, 7:57:53 PM2/12/09
to Clojure
If no one knows of any existing conventions, does anyone have ideas
for conventions?

Jeffrey Straszheim

unread,
Feb 12, 2009, 8:07:34 PM2/12/09
to clo...@googlegroups.com
Well, there is the IO! macro to wrap side effects.  This works with the transactions mechanism.

So foo! does show up, but is not followed rigorously.

Michael Wood

unread,
Feb 14, 2009, 4:15:29 AM2/14/09
to clo...@googlegroups.com
On Fri, Feb 13, 2009 at 3:07 AM, Jeffrey Straszheim
<straszhe...@gmail.com> wrote:
> Well, there is the IO! macro to wrap side effects. This works with the
> transactions mechanism.

Yes, see also (find-doc "!").

> So foo! does show up, but is not followed rigorously.

There is also do- (doall, dorun, doseq, dotimes, etc.)

> On Thu, Feb 12, 2009 at 7:57 PM, Kevin Albrecht <only...@gmail.com> wrote:
>>
>> If no one knows of any existing conventions, does anyone have ideas
>> for conventions?

--
Michael Wood <esio...@gmail.com>

Reply all
Reply to author
Forward
0 new messages