Clojure

Scopes

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Add the scope system for dealing with resource lifetime management

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/2
Hide
Assembla Importer added a comment -

richhickey said: Updating tickets (#8, #42, #113, #2, #20, #94, #96, #104, #119, #124, #127, #149, #162)

Show
Assembla Importer added a comment - richhickey said: Updating tickets (#8, #42, #113, #2, #20, #94, #96, #104, #119, #124, #127, #149, #162)
Hide
Stuart Halloway added a comment -

Patch demonstrates idea, not ready for prime time.

Show
Stuart Halloway added a comment - Patch demonstrates idea, not ready for prime time.
Stuart Halloway made changes -
Field Original Value New Value
Attachment scopes-spike.patch [ 10275 ]
Reporter Assembla Importer [ importer ]
Priority Major [ 3 ]
Kevin Downey made changes -
Comment [ I know the patch is just a demo, but it does restrict scopes to only dealing with closeables vs. what is demoed at http://paste.lisp.org/display/73838

the patch also doesn't contain the notion of different kinds of clean up to run depending on how you exit from a scope (exception, normal, either)

I have a little code I wrote inspired by the gist above, unfortunately I checked it into clojurebot and never bothered to spin it off into a library otherwise it might have seen some use in the wild https://github.com/hiredman/clojurebot/blob/master/src/hiredman/horizon.clj (sorry for the formatting). ]
Hide
Tassilo Horn added a comment - - edited

I think the decision of having to specify either a Closeable resource or a close function for an existing non-Closeable resource in with-open is quite awkward, because they have completely different meaning.

  (let [foo (open-my-custom-resource "foo.bar")]
    (with-open [r (reader "foo.txt")
                foo #(.terminate foo)]
      (do-stuff r foo)))

I think a CloseableResource protocol that can be extended to custom types as implemented in the patch to CLJ-308 is somewhat easier to use. Extend it once, and then you can use open-my-custom-resource in with-open just like reader/writer and friends...

That said, Scopes can still be useful, but I'd vote for handling the "how should that resource be closed" question by a protocol. Then the with-open helper can simply add

(swap! *scope* conj (fn [] (clojure.core.protocols/close ~(bindings 0))))

and cleanup-scope only needs to apply each fn without having to distinguish Closeables from fns.

Show
Tassilo Horn added a comment - - edited I think the decision of having to specify either a Closeable resource or a close function for an existing non-Closeable resource in with-open is quite awkward, because they have completely different meaning.
  (let [foo (open-my-custom-resource "foo.bar")]
    (with-open [r (reader "foo.txt")
                foo #(.terminate foo)]
      (do-stuff r foo)))
I think a CloseableResource protocol that can be extended to custom types as implemented in the patch to CLJ-308 is somewhat easier to use. Extend it once, and then you can use open-my-custom-resource in with-open just like reader/writer and friends... That said, Scopes can still be useful, but I'd vote for handling the "how should that resource be closed" question by a protocol. Then the with-open helper can simply add
(swap! *scope* conj (fn [] (clojure.core.protocols/close ~(bindings 0))))
and cleanup-scope only needs to apply each fn without having to distinguish Closeables from fns.
Alex Miller made changes -
Fix Version/s Approved Backlog [ 10034 ]
Fix Version/s Backlog [ 10035 ]
Alex Miller made changes -
Fix Version/s Backlog [ 10035 ]

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated: