On Oct 15, 11:13 pm, Timothy Pratley <[EMAIL PROTECTED]> wrote:
> Thanks so much for all the replies, that showed the way to what I
> wanted (simplified example using substring):
>
> (defn lazy-self [me]
>   ((fn rfib [a] (lazy-cons a (rfib a))) me))
> (defmacro map-obj [jobj jmeth argbinds & colls]
>   `(map (memfn ~jmeth [EMAIL PROTECTED]) (lazy-self ~jobj) [EMAIL PROTECTED]))
>
> (map-obj "Timothy" substring (i j) (iterate inc 0) [3 5 4])
>
> => ("Tim" "imot" "mo")
>
> ie: I was able to create a macro map-obj which will take a java object
> and map a method to a given binding+input collection
>
> Just a few follow on questions...
> 1) Is there any way to do away with the input bindings altogether? map
> doesn't need input bindings, but memfn does. I don't quite grasp why
> they are needed for memfn, or how to construct an input binding based
> on the number of collections. ie: I would need to generate a list of
> symbols the size of the number of collections (map gensym colls) ????
> I know that code wont work, but there must be a way.
> 2) Is there a better way than my creation of a lazy-self function, or
> is this pretty much the right thing to do?
> 3) Would I be better off making a macro that expands into a (doto
> statement?
>

I think you've gotten off track by pursuing the use of memfn here when
it isn't a good fit. Presuming your points are 2-element vectors, this
works:

(import '(javax.media.j3d BranchGroup LineArray Shape3D)
        '(javax.vecmath Point3f))

(def #^BranchGroup *scene-graph* (BranchGroup.))

(defn poly [label points]
  (let [la (LineArray. (count points) LineArray/COORDINATES)]
    (dorun
     (map (fn [idx [x y]]
            (.setCoordinate la (int idx) (Point3f. x y 0)))
          (iterate inc 0) points))
    (.addChild *scene-graph* (Shape3D. la))))



If you wanted to use memfn, it would have to look like this:

(defn poly [label points]
  (let [la (LineArray. (count points) LineArray/COORDINATES)]
    (dorun
     (map (memfn setCoordinate idx p3)
          (repeat la)
          (iterate inc 0)
          (map (fn [[x y]] (Point3f. x y 0)) points)))
    (.addChild *scene-graph* (Shape3D. la))))

Which feels weird, because you are not mapping the memfn across target
'this-es', so you have to repeat the target. Note that in the memfn
case, the call will be use reflection, as there is not a way to convey
the type info through memfn. The other code uses no reflection.

Rich

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to