Thanks to excellent feedback, I now realize my code was overly verbose, a
common phenomenon among beginners in many a computer language.
As an example, the newer version replaces this:
===
>
> (ns test-project.synmods)
>
> (defn add-open
> [edges]
> (let [[a b c d e f] edges
> [a2 b2 c2 d2 e2 f2] (map (fn [x] (* x x)) edges )]
> (do
> (reduce + [
> (reduce * [f2 a2 b2])
> (reduce * [d2 a2 c2])
> (reduce * [a2 b2 e2])
> (reduce * [c2 b2 d2])
> (reduce * [e2 c2 a2])
> (reduce * [f2 c2 b2])
> (reduce * [e2 d2 a2])
> (reduce * [b2 d2 f2])
> (reduce * [b2 e2 f2])
> (reduce * [d2 e2 c2])
> (reduce * [a2 f2 e2])
> (reduce * [d2 f2 c2])])
> )))
>
>
... with this:
(defn add-open
[edges]
(let [[a b c d e f] edges
[a2 b2 c2 d2 e2 f2] (map (fn [x] (* x x)) edges )]
(+ (* f2 a2 b2)
(* d2 a2 c2)
(* a2 b2 e2)
(* c2 b2 d2)
(* e2 c2 a2)
(* f2 c2 b2)
(* e2 d2 a2)
(* b2 d2 f2)
(* b2 e2 f2)
(* d2 e2 c2)
(* a2 f2 e2)
(* d2 f2 c2))
))
Much simpler! Thank you. I'll look into testing features.
In my Python version of the above, I do in fact, invoke the unittest framework.
Kirby
--
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
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.