Re: Improving a nested if, or How to use multimethods the right way.

2013-09-05 Thread Alex Baranosky
I'd just use a cond to flatten a nested if. That's usually all you need, imo. On Thu, Sep 5, 2013 at 1:07 PM, Bruno Kim Medeiros Cesar brunokim...@gmail.com wrote: Thanks for your suggestion, didn't know about that! One of the things that made someone say that Clojure looks like a language

Re: Improving a nested if, or How to use multimethods the right way.

2013-09-05 Thread Alex Baranosky
;; Better yet... (if (or (and (multi? graph) (not= 2 (count edge))) (and (looped? graph) (not (distinct? edge graph (let [e (if (directed? edge) (vec edge) (set edge))] (update-in graph [:edges] conj e On Thu, Sep 5, 2013 at 2:22 PM, Alex Baranosky

Re: Improving a nested if, or How to use multimethods the right way.

2013-09-05 Thread Bruno Kim Medeiros Cesar
Thanks for your suggestion, didn't know about that! One of the things that made someone say that Clojure looks like a language from the near future. However, I'm having a hard time using it with its full power. Could you recommend any other resource, besides the overview page on github, to

Re: Improving a nested if, or How to use multimethods the right way.

2013-09-05 Thread Bruno Kim Medeiros Cesar
Thanks, Alex, I was going down an over-engineering rabbit hole. Your solution just lacks a not before multi? and looped?. On Thursday, September 5, 2013 6:24:13 PM UTC-3, Alex Baranosky wrote: ;; Better yet... (if (or (and (multi? graph) (not= 2 (count edge))) (and (looped? graph)

Improving a nested if, or How to use multimethods the right way.

2013-09-04 Thread Bruno Kim Medeiros Cesar
I'm writing (another) basic graph library, and would like to treat inputs depending on the type of the graph. A graph can be - Directed, in which case edges are vectors. Otherwise, edges are sets; - Looped, allowing edges from a node to itself; - Pseudo (or multi), allowing multiples

Re: Improving a nested if, or How to use multimethods the right way.

2013-09-04 Thread Leonardo Borges
You could use pattern matching with core.match On 05/09/2013 6:57 AM, Bruno Kim Medeiros Cesar brunokim...@gmail.com wrote: I'm writing (another) basic graph library, and would like to treat inputs depending on the type of the graph. A graph can be - Directed, in which case edges are