Re: gen-class and state...

2011-03-30 Thread Stuart Sierra
On Sunday, March 27, 2011 6:17:59 AM UTC-4, Stefan Sigurdsson wrote: How do you guys normally manage resources when using lazy sequences? You have to manage resources at a larger scope that encompasses all your use of the lazy sequence. The quick-and-dirty solution is to use `doall` inside

Re: gen-class and state...

2011-03-28 Thread Jules
So I have come up with a solution to my desire to move to defprotocol/ type in spite of my requirement for gen-class' init/post-init methods : (def protocol Resource (open [this]) (close [this]) ... ) (deftype ResourceImpl [resource] Resource (open [this]...) (close [this] (.close

Re: gen-class and state...

2011-03-27 Thread Stefan Sigurdsson
How do you guys normally manage resources when using lazy sequences? I was playing around with this question, and I looked into extending line-seq to take a file path parameter that is coerced to reader: (defn line-seq ([^java.io.BufferedReader rdr] (when-let [line

Re: gen-class and state...

2011-03-27 Thread Stefan Sigurdsson
Aieh, I oversimplified a bit here, and forgot about not being able to overload with the same arity, without multimethods. Here is the actual code I was experimenting with, which actually runs... (defn- read-seq- [reader extract advance] (let [segment (extract reader) reader (advance

Re: gen-class and state...

2011-03-24 Thread Jules
Guys, Thanks for your replies - I'm glad I posted as this is exactly what I was looking for. I wish I had found Stuart's article when he wrote it. I had an inkling that my gen-class struggles were out of date - now I can go and rework all that code :-) Problem solved. Thanks again, Jules

Re: gen-class and state...

2011-03-24 Thread Ulises
Sorry for hijacking but I wouldn't mind some clarification on the subject. Right now I can get java classes and interfaces with defprotocol and defrecord and the world is good. Can somebody please educate me in the uses/needs for :gen-class and friends? Keep in mind that I haven't really done

Re: gen-class and state...

2011-03-24 Thread Meikel Brandmeyer
Hi, On 24 Mrz., 10:40, Ulises ulises.cerv...@gmail.com wrote: Can somebody please educate me in the uses/needs for :gen-class and friends? You need gen-class when you want (or have to) derive from another class. defrecord/deftype/reify don't allow that, while gen-class/proxy do. Sincerely

Re: gen-class and state...

2011-03-24 Thread Ulises
You need gen-class when you want (or have to) derive from another class. defrecord/deftype/reify don't allow that, while gen-class/proxy do. I suppose this is for when you want to add fields to an already existing class? (I'm assuming that adding methods could be done with

Re: gen-class and state...

2011-03-24 Thread Jules
Stuart, I still think in a very OO way - which is probably why I am having difficulty with this :-) A common OO pattern is to encapsulate complex resource acquisition/release within a class. I can do this with gen-class - since I control ctor args and the instances initial state, as well as

Re: gen-class and state...

2011-03-24 Thread Stuart Sierra
A typical pattern for resource management is a function or macro like `with-open-file`. -S -- 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 -

gen-class and state...

2011-03-23 Thread Jules
lookups one to fetch the immutable part from the .state field and one to lookup some useful piece of data in it. I'd like to reduce this to one lookup, directly into an immutable field in the POJO. Why doesn't gen-class allow e.g. :state [^Integer i ^String s ] in a more record like way

Re: gen-class and state...

2011-03-23 Thread Ken Wesson
On Wed, Mar 23, 2011 at 3:43 AM, Jules jules.gosn...@gmail.com wrote: I only have a brief posting window this morning (I have to leave for work) so have not researched this as well as I should before coming to the list - so please forgive if this is a bit lame... Should I still be using

Re: gen-class and state...

2011-03-23 Thread Stuart Sierra
Ahead-of-time compiled (AOT) code with `defprotocol` and `defrecord` creates interfaces and classes you can access from Java. You don't need gen-class, which is usually only necessary for public static void main methods and edge-case Java interop problems. I wrote about this on IBM