Thanks for the tip Max, so you mean like this?

(defn cases->event-stream [cases features-extractor labeler]
  (let [remaining (atom cases)]
    (reify opennlp.model.EventStream
      (next [this] (let [current (first @remaining)]
                     (swap! remaining rest)
                     (case->event current features-extractor labeler)))
      (hasNext [this] (not (empty? @remaining))))))

May I ask why that would be faster? And when proxy is preferred over reify?

Joachim.

2013/2/14 Max Penet <m...@qbits.cc>

>
> Also It looks like you could use reify instead of proxy here, it would
> improve performance.
>
> http://clojuredocs.org/clojure_core/clojure.core/reify
>
> - Max
>
>
> On Thursday, February 14, 2013 3:26:02 PM UTC+1, Ulises wrote:
>
>> Without testing or anything that looks reasonable enough. I'm sure that
>> there are plenty caveats around infinite seqs, etc. though.
>>
>>
>> On 14 February 2013 14:22, Joachim De Beule <joachim....@gmail.com>wrote:
>>
>>> Thanks! So you mean like this (assuming some function elt->event):
>>>
>>> (defn seq->event-stream [input-seq]
>>>   (let [remaining (atom input-seq)]
>>>     (proxy [EventStream] []
>>>       (next [] (let [current (first @remaining)]
>>>                     (swap! remaining rest)
>>>                     (elt->event current)))
>>>       (hasNext [] (not (empty? @remaining))))))
>>>
>>>
>>>
>>> 2013/2/14 Ulises <ulises....@gmail.com>
>>>
>>>> How about having your methods access an atom provided in a closure like
>>>> it's done here: http://kotka.de/blog/**2010/03/proxy_gen-class_**
>>>> little_brother.html<http://kotka.de/blog/2010/03/proxy_gen-class_little_brother.html>
>>>>
>>>> U
>>>>
>>>>
>>>> On 14 February 2013 13:58, Joachim De Beule <joachim....@gmail.com>wrote:
>>>>
>>>>> Hi All,
>>>>>
>>>>> I want to turn a clojure sequence into an 'EventStream' java interface
>>>>> in clojure (see http://opennlp.apache.**org/documentation/1.5.2-**
>>>>> incubating/apidocs/opennlp-**maxent/index.html<http://opennlp.apache.org/documentation/1.5.2-incubating/apidocs/opennlp-maxent/index.html>).
>>>>> Basically this is an object that implements next() and hasNext() methods.
>>>>>
>>>>> I know this can be done with proxy:
>>>>>
>>>>> (proxy [EventStream] []
>>>>>    (hasNext [] ...)
>>>>>    (next [] (Event. ...) ...))
>>>>>
>>>>> What I am not sure about is how to deal with state. More precisely,
>>>>> the object returned by the above call to proxy obviously must somehow keep
>>>>> a pointer to the current position in the input sequence and increment the
>>>>> index after a call to next() etc.
>>>>>
>>>>> Any ideas on how to best do something like this?
>>>>>
>>>>> Thanks a lot!
>>>>> Joachim.
>>>>>
>>>>>
>>>>> --
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Clojure" group.
>>>>> To post to this group, send email to clo...@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+u...@**googlegroups.com
>>>>>
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/**group/clojure?hl=en<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+u...@**googlegroups.com.
>>>>>
>>>>> For more options, visit 
>>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>>> .
>>>>>
>>>>>
>>>>>
>>>>
>>>>  --
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Clojure" group.
>>>> To post to this group, send email to clo...@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+u...@**googlegroups.com
>>>>
>>>> For more options, visit this group at
>>>> http://groups.google.com/**group/clojure?hl=en<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+u...@**googlegroups.com.
>>>>
>>>> For more options, visit 
>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>> .
>>>>
>>>>
>>>>
>>>
>>>  --
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@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+u...@**googlegroups.com
>>>
>>> For more options, visit this group at
>>> http://groups.google.com/**group/clojure?hl=en<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+u...@**googlegroups.com.
>>>
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>
>>  --
> --
> 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.
>
>
>

-- 
-- 
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.


Reply via email to