map can take more than one argument. If it has N arguments, it calls f
with N arguments, each taken from the Nth value of each collection. So
you should be able to pass in an infinite sequence like this UNTESTED
code:
(map f coll (range (count coll)))
Jim
>
>
> Specifically what I'm struggling with:
>
> (def *scene-graph* (new javax.media.j3d.BranchGroup))
>
> (defn poly [label points]
> (let [la (new javax.media.j3d.LineArray (count points)
> (.COORDINATES javax.media.j3d.LineArray)]
> (map (memfn javax.media.j3d.LineArray.setCoordinate idx (new
> javax.vecmath.Point3f x y 0) points)
> (.addChild *scene-graph* (new javax.media.j3d.Shape3D la))))
>
> The intention being that points is a list of x,y coordinates
> I construct a LineArray which is the size of points
> then for every point I need to call setCoordinate(index, Point3f(x,y))
> The LineArray then makes a Shape3D which can be added to the scene
> graph.
>
>
> Regards,
> Tim.
>
>
>
>
>
> >
>
--
Jim Menard, ji...@io.com, jim.m...@gmail.com
http://www.io.com/~jimm/
> map can take more than one argument. If it has N arguments, it calls f
> with N arguments, each taken from the Nth value of each collection.
Too many "N"s. Restated, map takes a function f and N collections,
each of which should have the same number of elements M. It calls f M
times with N arguments each time, using the i'th element of each of
the collections. (Darn, I'm wordy :-)
Jim
Rather than (range (count coll)), I would use (iterate inc 0), which
incurs no overhead for counting the argument.
Best,
Graham
You're right; that's better. I'm a Clojure newbie, so I appreciate
learning the faster/smaller/more idiomatic way to do things.
Jim