I don't know if it's of any worth but I switched from 1.3.0-alpha2-
SNAPSHOT to 1.2 and my problems are gone. The simplest way I found to
reproduce the error I was having in 1.3 was to paste this following
function into a repl. The function is meaningless but I figure it
should at least compile.
(defn search [condition shape plane]
(let [mod-nth (fn [coll x] (nth coll (mod x (count coll))))
ceil (fn [x] (inc (int x)))]
(loop [accum 0 step (ceil (/ (count (:points shape)) 2)) from -1]
(condp condition (vector plane (mod-nth (:points shape) accum))
(vector plane (mod-nth (:points shape) (+ accum step)))
(if (= from (+ accum step))
[(vector plane (mod-nth (:points shape) (+ accum step)))
(mod-nth (:points shape) from) (mod-nth (:points shape)
accum)]
(recur (+ accum step) (ceil (/ step 2)) accum))
(vector plane (mod-nth (:points shape) (- accum step)))
(if (= from (- accum step))
[(vector plane (mod-nth (:points shape) (- accum step)))
(mod-nth (:points shape) from) (mod-nth (:points shape)
accum)]
(recur (- accum step) (ceil (/ step 2)) accum))
[(vector plane (mod-nth (:points shape) accum))
(mod-nth (:points shape) accum)]))))
On Nov 1, 12:21 am, Meikel Brandmeyer <[email protected]> wrote:
> Hi,
>
> your code is really hard to understand. Please let let to be your
> friend! I extracted things a little bit and put everything in a let.
> Since I have no clue about collission detection in physics engines I
> derived the local names from the operations done "i"nc, "d"ec, etc.
> More meaningful names conveying domain information are left to the
> astute reader as an excercise. ;-)
>
> You probably can replace defstruct with defrecord. defrecord will
> supersede defstruct eventually.
>
> > (defstruct projection-struct :start :stop :start-points :stop-points)
> > (println 1)
>
> Here you can use the type function. Also note: your method won't work.
> Your dispatch function should match your methods in arity. It may take
> more if they are "don't cares" for the dispatch.
>
> > (defmulti projection (fn [shape & _] (type shape)))
> > (println 2)
>
> As I said, some cleanup with let (hopefully without messing things
> up). Also you cannot "call" integers with vectors. You have to use
> nth.
>
>
>
> > (defmethod projection :polygon
> > [shape plane]
> > (let [points (:points shape)
> > npoints (int (count points))
> > dotp #(->> % (nth points) (dot plane))
> > search (fn [condition]
> > (loop [accum (int 0)
> > step npoints
> > from (int -1)]
> > (let [step (inc (/ step (int 2)))
> > iaccum (+ accum step)
> > daccum (- accum step)
> > naccum (mod iaccum npoints)
> > paccum (mod daccum npoints)
> > dotp-accum (dotp accum)
> > dotp-naccum (dotp naccum)
> > dotp-paccum (dotp paccum)
> > apoints (nth points accum)
> > fpoints (nth points from)]
> > (condp condition dotp-accum
> > dotp-naccum (if (= from iaccum)
> > [dotp-naccum [fpoints apoints]]
> > (recur naccum step accum))
> > dotp-paccum (if (= from daccum)
> > [dotp-paccum [fpoints apoints]]
> > (recur paccum step accum))
> > [dotp-accum [apoints]]))))
> > [start start-points] (search <=)
> > [end end-points] (search >=)]
> > (struct projection-struct start end start-points end-points)))
> > (println 3)
>
> On 1 Nov., 01:10, Jarl Haggerty <[email protected]> wrote:
>
> > I've also redefined the math functions to work with vectors and
> > matrices.
>
> Hmm.. I would suggest to stay away from such experiments until you
> have a better understanding on Clojure.
>
> That all said: I don't have a problem for your real problem. I don't
> see an obvious reason why the defmethod should hang. I would expect
> some quirk in your environment from outside this code snippet.
>
> Sincerely
> Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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