Coincidentally, I just found this in 
clojure/core/protocols.clj<https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/protocols.clj>
 (not 
that this is necessarily the best way to do this):

(def arr-impl
  '(internal-reduce
       [a-seq f val]
       (let [arr (.array a-seq)]
         (loop [i (.index a-seq)
                val val]
           (if (< i (alength arr))
             (let [ret (f val (aget arr i))]
                (if (reduced? ret)
                  @ret
                  (recur (inc i) ret)))
             val)))))

(defn- emit-array-impls*
  [syms]
  (apply
   concat
   (map
    (fn [s]
      [(symbol (str "clojure.lang.ArraySeq$ArraySeq_" s))
       arr-impl])
    syms)))

(defmacro emit-array-impls
  [& syms]
  `(extend-protocol InternalReduce
     ~@(emit-array-impls* syms)))

(emit-array-impls int long float double byte char boolean)
On Saturday, February 23, 2013 4:03:02 AM UTC-8, Jim foo.bar wrote:
>
> I seem to be unable to quote a form and then repeatedly pass it inside 
> the extend-protocol macro...something like this: 
>
> (def ^:private co-stub 
> '(run [this ^String text] 
>     (let [ann (edu.stanford.nlp.pipeline.Annotation. text)] 
>       (.annotate this ann) ann))) 
>
>
> (extend-protocol IComponent 
> edu.stanford.nlp.pipeline.POSTaggerAnnotator      co-stub 
> edu.stanford.nlp.pipeline.PTBTokenizerAnnotator   co-stub 
> edu.stanford.nlp.pipeline.WordsToSentencesAnnotator co-stub 
> edu.stanford.nlp.pipeline.CleanXmlAnnotator       co-stub 
> edu.stanford.nlp.pipeline.MorphaAnnotator         co-stub 
> edu.stanford.nlp.pipeline.NERCombinerAnnotator    co-stub 
> edu.stanford.nlp.pipeline.RegexNERAnnotator       co-stub 
> edu.stanford.nlp.pipeline.TrueCaseAnnotator       co-stub 
> edu.stanford.nlp.pipeline.ParserAnnotator         co-stub 
> edu.stanford.nlp.pipeline.DeterministicCorefAnnotator co-stub 
> ) 
>
> neither quoted version nor the back-quoted version work...The former 
> throws : 
> ClassCastException clojure.lang.PersistentList cannot be cast to 
> java.lang.Class  clojure.core/implements? (core_deftype.clj:512) 
>
> and the latter throws: 
>
> ClassCastException clojure.lang.Cons cannot be cast to java.lang.Class   
> clojure.core/implements? (core_deftype.clj:512) 
>
> any macro-gurus around? 
>
> Jim 
>

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