I have released version 0.1.0 of scopes, a little library for resource scopes. It can be used to establish a resource scope with the with-resource-scope macro. Within the dynamic extent of that macro one can register a resource with the scoped! function so that when the macrco block goes out of scope .close is called on the registered resource.
An object and function can also be registered with (scoped! x (fn [x] ...)) so that when the macro block goes out of scope the function will be called and given x as an argument. There is also a shorthand function called scoped-thunk! that will register a thunk (a function taking no arguments) to be called when the macro block goes out of scope. The scopes library also defines a function named closeable? that will return true if its argument implements java.lang.AutoCloseable. Because scopes uses the java.lang.AutoCloseable interface and the exception supression mechanism, it is only compatible with Java 7. Finally, there is also a scopes-magic artifact, and when it is on the classpath it will automatically pull in the scopes library and add with-resource-scope, scoped!, scoped-thunk!, and closeable? to clojure.core so that they are automatically available everywhere with out having to be imported. I'm not saying that this is necessarily a good idea, but there it is. :) https://clojars.org/pjstadig/scopes https://clojars.org/pjstadig/scopes-magic Paul -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.