Re: "when" function

2012-05-21 Thread Christian Guimaraes
Hi, I think that multimethods will fit better in my case, since I have more than three ID's to handle. Thank you all for the answers. -- christian. On Mon, May 21, 2012 at 5:04 PM, Timothy Baldridge wrote: > > A multimethod might also be an appropriate way forward for you. > > +1 For multimeth

Re: "when" function

2012-05-21 Thread Timothy Baldridge
> A multimethod might also be an appropriate way forward for you. +1 For multimethods, don't hardcode it if you don'tt have to. Timothy -- 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 Not

Re: "when" function

2012-05-21 Thread Bronsa
or simply use `case` (case group-identifier "ID1" (handle-id1 line) "ID2" (handle-id2 line) "ID3" (handle-id3 line)) 2012/5/21 Timothy Baldridge > In this case I prefer either: > > (cond (= group-identifier "ID1") >(handle-id1 line) > (= group-identifier "ID2")

Re: "when" function

2012-05-21 Thread Jonas
On Monday, May 21, 2012 6:54:28 PM UTC+3, Christian Guimaraes wrote: > > Hi all, > > I'm struggling with "when" code structures and my imperative mindset. > > What is the better approach (or functional approach) to work with a code > like the below? > > (defn parse-group [group-identifier line]

Re: "when" function

2012-05-21 Thread Sean Corfield
On Mon, May 21, 2012 at 8:54 AM, Christian Guimaraes wrote: > What is the better approach (or functional approach) to work with a code > like the below? A simple translation to condp: (defn parse-group [group-identifier line] (condp = group-identifier "ID1" (handle-id1 line) "ID2" (han

Re: "when" function

2012-05-21 Thread Jay Fields
I'm surprised no one went for condp (defn parse-group [group-identifier line] (condp = group-identifier "ID1" (handle-id1 line) "ID2" (handle-id2 line) "ID3" (handle-id3 line) (handle-unknown-id line))) or something like that... On Mon, May 21, 2012 at 11:59 AM, Timothy Baldri

Re: "when" function

2012-05-21 Thread Timothy Baldridge
In this case I prefer either: (cond (= group-identifier "ID1") (handle-id1 line) (= group-identifier "ID2") (handle-id2 line) (= group-identifier "ID3") (handle-id3 line)) Or just use core.match: (match [group-identifier] ["ID1"

Re: "when" function

2012-05-21 Thread Bill Caputo
On May 21, 2012, at 10:54 AM, Christian Guimaraes wrote: > I'm struggling with "when" code structures and my imperative mindset. > > What is the better approach (or functional approach) to work with a code like > the below? I think you're looking for cond (from memory, syntax might be wrong): (

"when" function

2012-05-21 Thread Christian Guimaraes
Hi all, I'm struggling with "when" code structures and my imperative mindset. What is the better approach (or functional approach) to work with a code like the below? (defn parse-group [group-identifier line] (when (= group-identifier "ID1") (handle-id1 line)) (when (= group-identifier "