Shouldn't "doto" be named just "with"

4 views
Skip to first unread message

Dimiter "malkia" Stanev

unread,
Mar 6, 2009, 6:13:51 PM3/6/09
to Clojure
I've just started using doto, after seeing the celsius example on the
Clojure page, but It brought back memories from Pascal days -
http://csci.csusb.edu/dick/samples/pascal.syntax.html#with_statement

It's probably nothing, but to me (with x (.Function1) (.Function2))
seems more readable than (doto). Off course I'm already used to doto
(spend almost 10 minutes on it), and Common Lisp learned me to be okay
with any names, because once you learn it, the name is just a memo to
what the semantics are.

But still It might be more approachable to a newbie to use "with",
rather than "doto". Then again, the whole "with-" convention is a
whole other topic.

Just wanted to share with you!

Laurent PETIT

unread,
Mar 6, 2009, 6:23:18 PM3/6/09
to clo...@googlegroups.com
Hello,

I'm not sure about this, but I think doto is named after the convention that a lot of side effecting functions/macros/special forms follow : share the "do" prefix if the name implies that there will be side effects.

And indeed, if you use doto with more than one following expression, then this list of expression will generate side effects (mutating the target object, at a minimum).

My 0,02€,

--
Laurent

2009/3/7 Dimiter malkia Stanev <mal...@gmail.com>

Meikel Brandmeyer

unread,
Mar 6, 2009, 6:37:42 PM3/6/09
to clo...@googlegroups.com
Hi,

Am 07.03.2009 um 00:23 schrieb Laurent PETIT:

> I'm not sure about this, but I think doto is named after the
> convention that a lot of side effecting functions/macros/special
> forms follow : share the "do" prefix if the name implies that there
> will be side effects.
>
> And indeed, if you use doto with more than one following expression,
> then this list of expression will generate side effects (mutating
> the target object, at a minimum).

I think "doto" is actually a good name. In contrast
to ->, which uses the return value of the expressions
doto always calls the given functions or methods
using the initial thing. So it "does" the function
calls "to" the thing.

Together with the points Laurent mentioned
about the do-prefix indicating side-effects and
the slightly different notion of the with-something
blocks, I think doto is just good enough a name.

Just, my 2¢ and YMMV.

Sincerely
Meikel

Dimiter "malkia" Stanev

unread,
Mar 6, 2009, 7:36:28 PM3/6/09
to Clojure
Thanks for the explanation guys!

Having learned other languages, sometimes makes you wanna have the
MEMORY UNDO FEATURE!
>  smime.p7s
> 5KViewDownload

RZez...@gmail.com

unread,
Mar 6, 2009, 7:51:39 PM3/6/09
to Clojure
I think good arguments have been made for "doto," but I must say I
prefer "with" slightly more.

FWIW, Groovy calls it "with."

http://javajeff.blogspot.com/2008/11/getting-groovy-with-with.html

The great thing about Clojure is that if this really bothered me I
could easily take matters into my own hands.

(defmacro with [x & forms] `(doto ~x ~@forms))

Clojure rocks!

On Mar 6, 7:36 pm, "Dimiter \"malkia\" Stanev" <mal...@gmail.com>
wrote:

Dan

unread,
Mar 7, 2009, 1:31:41 PM3/7/09
to clo...@googlegroups.com
On Fri, Mar 6, 2009 at 7:51 PM, rzez...@gmail.com <RZez...@gmail.com> wrote:
>
> I think good arguments have been made for "doto," but I must say I
> prefer "with" slightly more.

with can mean different things in different languages. In javascript,
it means the same thing as doto in clojure but in Python (and many
others I'm told) it means that the resource I used in the with block
should be automatically cleaned (the file should be closed, the
connexion should be freed, etc.) at the end of the block.

doto is not ambiguous

Beside, clojure itself uses the word with in many of its functions/macros.

Dimiter "malkia" Stanev

unread,
Mar 7, 2009, 3:59:52 PM3/7/09
to Clojure
Yes, that's a very good point. For example "with" in Common Lisp is
used also when dealing with external resources (with-open-file, etc.).
And also the point about other with- usages.

On Mar 7, 10:31 am, Dan <redalas...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages