Re: Sequential conditional transforms of an argument

2013-07-08 Thread Bob Hutchison
On 2013-07-08, at 2:40 AM, Laurent PETIT wrote: > thank you all for your answer. > > So to go back to my original concern, there does not seem to be a way > to do this as I intended by just combining the existing features in > core. > I'm not sure what you're asking for here. Do you mean *in-

Re: Sequential conditional transforms of an argument

2013-07-07 Thread Laurent PETIT
thank you all for your answer. So to go back to my original concern, there does not seem to be a way to do this as I intended by just combining the existing features in core. Cheers, -- Laurent 2013/7/8 Yoshinori Kohyama : > Hi Laurent, > > How about a macro like below? > > (defmacro tt >

Re: Sequential conditional transforms of an argument

2013-07-07 Thread Yoshinori Kohyama
Hi Laurent, How about a macro like below? (defmacro tt ([x] x) ([x ts tr & more] `(tt (if (~ts ~x) (~tr ~x) ~x) ~@more))) To use this, (tt x test1 transform1 test2 transform2 test3 transform3) This doesn't work even number of arguments as you see. HTH, Y.Kohyama -- -- You recei

Re: Sequential conditional transforms of an argument

2013-07-05 Thread Mikera
On Friday, 5 July 2013 16:52:10 UTC+1, Laurent PETIT wrote: > 2013/7/5 Mikera >: > > I really like the as-> macro for this kind of thing. > > > > (as-> (something) x > > (if (test1 x) (transform1 x) x) > > (if (test2 x) (transform2 x) x) > > (do-something-else-with

Re: Sequential conditional transforms of an argument

2013-07-05 Thread Laurent PETIT
2013/7/5 Mikera : > I really like the as-> macro for this kind of thing. > > (as-> (something) x > (if (test1 x) (transform1 x) x) > (if (test2 x) (transform2 x) x) > (do-something-else-with x y) > (if (test3 x) (transform3 x) x)) > > Advantages: > - It's part of

Re: Sequential conditional transforms of an argument

2013-07-05 Thread Mikera
I really like the as-> macro for this kind of thing. (as-> (something) x (if (test1 x) (transform1 x) x) (if (test2 x) (transform2 x) x) (do-something-else-with x y) (if (test3 x) (transform3 x) x)) Advantages: - It's part of core in 1.5 - It's a macro and com

Re: Sequential conditional transforms of an argument

2013-07-05 Thread Thomas Heller
Hi, you could use a macro, but a simple function should suffice. I use something along the lines of (defn cond-transform [x & pairs] (reduce (fn [x [test-fn transform-fn]] (if (test-fn x) (transform-fn x) x)) x pairs)) ;; example

Sequential conditional transforms of an argument

2013-07-05 Thread Laurent PETIT
hello, More often than not, I'm facing code looking like this: (let [x (if (test1 x) (transform1 x) x) x (if (test2 x) (transform2 x) x) x (if (test3 x) (transform3 x) x)] x) Do you know of a better way to write this with only clojure.core functions? So far, I've had no success