I'm not sure if anyone's already done this, but I recently got tired of 
writing code that looked like this:

(let [a 1]



(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