Right, so if you use protocols, you'd just have one name:
add, sub, norm, len, neg
and use for both vectors and quadrays, rather than a v-add / q-add, etc.

If there are things that apply only to vectors and not quadrays, you could
make those their own protocol (or individual functions).

And of course, multimethods are yet another way to achieve polymorphism in
Clojure.  Multimethods would really shine if you want to get into
complicated mixtures of adding vectors and quadrays, etc., or dispatch on
something other than the type (e.g., maybe pre-normalized quadrays dispatch
to something more efficient).  Protocols (like traditional OO) can only
dispatch on the type of the first input.

One other code simplification tip: you can destructure in the parameter,
e.g., if you were to rewrite q-neg to be a plain function as opposed to a
protocol, you could still get convenient access to the member variables by
writing it like this:
(defn q-neg [{:keys [OA OB OC OD]}] (->Quadray (- OA)(- OB)(- OC) (- OD)))

http://www.john2x.com/blog/clojure-destructuring/



On Thu, Aug 6, 2015 at 1:52 PM, kirby urner <kirby.ur...@gmail.com> wrote:

>
>> Also, don't forget to explore the test framework versus global defs and
>> print statements.
>>
>> --
>>
>
>
> Excellent feedback Mark, thank you so much!
>
> This is exactly what I was hoping for.  I will be simplifying said code
> accordingly and posting it back.
>
> A great way to learn!
>
> I do think I might add the same protocol to a regular XYZ Vector defrecord
> type, but then that would mean changing the names maybe to v-add, v-sub
> etc. v for vector.
>
> I have intra-conversion twixt these exotic Quadray and XYZ coordinates,
> already in Python.
>
> Plus with vectors ** we expect:  angles between any two; polar coords;
> scalar grow-shrink; something like dot and cross product
>
> So I could flesh out the one protocol (inherits from Java interface I
> understand) and show how both vector notations share the same API.  That
> would seem an appropriate use of the syntax maybe?
>
> Related literature:  http://www.dividedspheres.com/
>
> Kirby
>
>
> ** in this implementation a "vector" is always tail-originating at some
> place we locally define as "the origin", so any to vectors will have the
> same origination point, meaning a "central angle" is implied.  For
> polyhedrons around the origin we build with Edges, each defined with two
> vectors; and with Faces (sets of Edges).  A similar notion of vector (vs.
> line segment) is found in
> http://www.amazon.com/Elementary-Linear-Algebra-Stewart-Venit/dp/0534951902
>
>
>
>
>
>
> 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 a topic in the
>> Google Groups "Clojure" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/clojure/RvHQPfBKJuM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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/d/optout.
>

-- 
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/d/optout.

Reply via email to