(set! *print-level* 8) ;;so you can see all of macroexpand-1 ;;;;;;MISC Utilities ;;;;;; ;;;;;; (defn mklst [item] (if (list? item) item (list item)))
(defn lassoc [item lst] (first (filter #(= (first (mklst %)) item) lst))) (defmacro llet [bind & body] `(let ~(vec (mapcat #(if-not (list? %) (list % nil) %) bind)) ~...@body)) (defmacro lcond [& cond] (let [bindings (mapcat #(list (first %) `(do ~@(rest %))) cond)] `(cond ~...@bindings))) ;;;;;; ;;;;;; ;;;;;; (defn condlet-binds [vars cl] (map (fn [bindform] (if (list? bindform) (cons (second (lassoc (first bindform) vars)) (rest bindform)))) (rest cl))) (defn condlet-clauses [vars cl bodfn] `(~(first cl) (llet ~(map second vars) (llet ~(condlet-binds vars cl) (~bodfn ~@(map second vars)))))) (defmacro condlet [clauses & body] (let [vars (map #(list % (gensym)) (distinct (map first (mapcat rest clauses)))) bodfn (gensym)] `(letfn ((~bodfn ~(vec (map first vars)) ~...@body)) (lcond ~@(map #(condlet-clauses vars % bodfn) clauses))))) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---