It's rare to get tired of this, because nobody does it: it's not
common because your interleaved statements are side-effecting only,
which is not encouraged in Clojure, and rarely needed. Certainly
sometimes it's the best way to do something, but not so often that I'd
become frustrated; if anything, having to write such irritating code
can serve as a good reminder that I shouldn't have so many
unrestrained side effects scattered through my logic.

On Oct 18, 9:01 am, JvJ <kfjwhee...@gmail.com> wrote:
> I'm not sure if anyone's done this before, but I'm fed up with writing code
> that looks like this:
>
> (let [a 1]
>    (println "this is a: " a)
>    (let [b 2]
>        (println "this is b: " b)
>        (let [c 3]
>             (println "this is c: " c)
>             (+ a b c))))
>
> I'd rather do something more like this:
> (-:>
>    (:= a 1) ;; Assign a to 1
>    (println "this is a: " a)
>    (:= b 2)
>    (println "this is b: " b)
>    (:= c 3)
>    (println "this is c: " c)
>    (+ a b c))
>
> I wrote a macro to do this, but I feel like it's such a simple thing that
> someone must have done it before, and it's probably better than mine.
> Does anyone know of anything like that?
>
> Here's the code for it in case anyone wants to use it:
>
> (ns cljutils.core)
>
> (defn- form-check
>   "Ensures the form represents an assignment.
> Such as (:= a 1)"
>   [form]
>   (and
>    (= 3 (count form))
>    (= := (first form))
>    (symbol? (second form))))
>
> (defn- iblk-fn
>   "Simulates imperative variable-assignments through nested
> let statements."
>   [& forms]
>   (let [form (first forms)
>         rforms (rest forms)]
>     (if-not form
>       nil
>       ;; Else
>       `(do
>          ~@(if (form-check form)
>              `((let [~(second form) ~(nth form 2)]
>                  ~(apply iblk-fn rforms)))
>              (let [[f r] (split-with (comp not form-check) forms)]
>                 (concat
>                  f
>                  (apply iblk-fn r))))))))
>
> (defmacro -:>
>   [& forms]
>   (apply iblk-fn forms))

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to