Re: My first Clojure program (and blog post about it)

2015-08-10 Thread kirby urner
Your way works because basically you are building two extra vectors which are implicitly getting destructured, but that's syntactically noisy and also a lot of extra computational work that is unneeded. -- Thanks! I cleaned it up a bunch:

Re: My first Clojure program (and blog post about it)

2015-08-10 Thread Mark Engelberg
On Sat, Aug 8, 2015 at 12:39 PM, kirby urner kirby.ur...@gmail.com wrote: (defrecord XYZray [OX OY OZ] VectorOps (norm [this] (this)) Should be (norm [this] this) not (norm [this] (this)), because the latter will try to invoke `this` as a function. (defn qray-to-xyzray [qray]

Re: My first Clojure program (and blog post about it)

2015-08-08 Thread kirby urner
On Thu, Aug 6, 2015 at 2:35 PM, Mark Engelberg mark.engelb...@gmail.com wrote: 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. I have done this vis-a-vis Quadrays and XYZrays as both

Re: My first Clojure program (and blog post about it)

2015-08-06 Thread kirby urner
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

Re: My first Clojure program (and blog post about it)

2015-08-06 Thread Mark Engelberg
On Thu, Aug 6, 2015 at 10:39 AM, kirby urner kirby.ur...@gmail.com wrote: (ns test-project.quadrays) (defprotocol Ops (q-add [this other]) (q-sub [this other]) (q-len [this]) (q-neg [this]) (q-norm [this])) (defrecord Quadray [OA OB OC OD] Ops (q-norm [this] (let [[a b c d] [(:OA

Re: My first Clojure program (and blog post about it)

2015-08-06 Thread Mark Engelberg
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

Re: My first Clojure program (and blog post about it)

2015-08-06 Thread kirby urner
On Thursday, July 30, 2015 at 6:38:11 PM UTC-7, kirby urner wrote: On Thu, Jul 30, 2015 at 6:14 PM, Leif wrote: This still seems very verbose to me. I think it is because the definition of open, opposite, and closed are implicit in the great big blocks of arithmetic you are doing. I

My first Clojure program (and blog post about it)

2015-07-30 Thread kirby urner
Greetings all. I'm new to Clojure (but not to programming) and wanted to document a first effort. The blog post: http://controlroom.blogspot.com/2015/07/ramping-up.html === (ns test-project.synmods) (defn add-open [edges] (let [[a b c d e f] edges [a2 b2 c2 d2 e2 f2] (map (fn

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread Amith George
Hi, From a cursory glance, I didn't really understand the domain, so the function names I used in my rewrite might seem silly. But I wanted to illustrate that there is a lot of repetition in your code. Also discrete functions (with proper names) can make the code easier to grok.

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread Mark Engelberg
Given that your functions expect a list of exactly 6 inputs, I'd be inclined to write these as functions that take 6 inputs, rather than a list. That way you get a meaningful error if they pass the wrong number of inputs. If you do prefer to keep them as-is, you can also shorten the code by a

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread Leif
This still seems very verbose to me. I think it is because the definition of open, opposite, and closed are implicit in the great big blocks of arithmetic you are doing. I think a useful exercise would be to define edges in terms of points, and maybe faces in terms of edges and an `face?`

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread Mark Engelberg
(println (format ...)) can be rewritten as (printf ...) if you add a \n to your string. A large chunk of your computations after the definitions appear to be global definitions and print messages to achieve some sort of unit testing. I encourage you to refactor this using clojure.test so you can

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread James Reeves
One quick suggestion is that arithmetic operations in Clojure frequently take multiple arguments. So: (reduce + [1 2 3]) Is equivalent to: (+ 1 2 3) In terms of style, variables are typically lower-case in Clojure except when referring to a class, interface or protocol. - James On 30

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread kirby urner
Excellent feedback so far, I thank experienced Clojure programmers for giving me tips. I may post a next version after incorporating some of this advice. Yes, I have much to learn! Kirby -- You received this message because you are subscribed to the Google Groups Clojure group. To post

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread kirby urner
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

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread kirby urner
On Thu, Jul 30, 2015 at 6:14 PM, Leif leif.poor...@gmail.com wrote: This still seems very verbose to me. I think it is because the definition of open, opposite, and closed are implicit in the great big blocks of arithmetic you are doing. I think a useful exercise would be to define edges in

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread kirby urner
On Thu, Jul 30, 2015 at 6:33 PM, Amith George strider...@gmail.com wrote: Hi, From a cursory glance, I didn't really understand the domain, so the function names I used in my rewrite might seem silly. But I wanted to illustrate that there is a lot of repetition in your code. Also discrete

Re: My first Clojure program (and blog post about it)

2015-07-30 Thread Mark Engelberg
The do's are unnecessary. On Thu, Jul 30, 2015 at 2:50 PM, James Reeves ja...@booleanknot.com wrote: One quick suggestion is that arithmetic operations in Clojure frequently take multiple arguments. So: (reduce + [1 2 3]) Is equivalent to: (+ 1 2 3) In terms of style, variables