with-open should use a close multimethod?

10 views
Skip to first unread message

Mike Hinchey

unread,
Aug 28, 2009, 4:27:04 AM8/28/09
to clo...@googlegroups.com
I have a suggestion for the with-open macro.  It calls .close when it's finished.  I'd like it to have a (defmulti close type) so it's behavior is extensible.  A standard method could be defined for java.io.Closeable and a :default method with no type hint.  I've come across a few cases where some external library defines what is essentially a close method but names it shutdown or disable, etc., and defining my own close method would be much easier than rewriting with-open.  This would also allow people to eliminate reflection for classes like sql Connection that were created before Closeable.

I'll submit a patch if it's wanted.  This would fit in core, or maybe contrib.duck-streams with a slightly different name.

-Mike

Seth

unread,
Aug 28, 2009, 7:07:12 AM8/28/09
to Clojure
Sounds good to me.

Chas Emerick

unread,
Aug 28, 2009, 9:41:24 AM8/28/09
to clo...@googlegroups.com
Definitely +1, yes.

- Chas

Sean Devlin

unread,
Aug 28, 2009, 9:54:09 AM8/28/09
to Clojure
+1

C. Florian Ebeling

unread,
Aug 28, 2009, 9:59:57 AM8/28/09
to clo...@googlegroups.com
+1

Coming across that problem just yesterday.
--
Florian Ebeling
florian...@gmail.com

J. McConnell

unread,
Aug 28, 2009, 10:03:06 AM8/28/09
to clo...@googlegroups.com
+1

Jarkko Oranen

unread,
Aug 28, 2009, 12:42:28 PM8/28/09
to Clojure
> I'll submit a patch if it's wanted.  This would fit in core, or maybe
> contrib.duck-streams with a slightly different name.

This should be in core I think, so that it can work with with-open—
unless we're going to duplicate with-open in contrib. :/

--
Jarkko
Reply all
Reply to author
Forward
0 new messages