On Sat, Feb 5, 2011 at 10:14, B Smith-Mannschott <bsmith.o...@gmail.com> wrote:
> I considered that, but decided against it because vector is the > conventional syntax for variable bindings in Clojure (let, fn, > defrecord, ...) Once I'd decided to do that, it became clear that the > first of the forms would become the initialization expression for the > binding. > > On the other hand, reusing the vector syntax is not entirely fitting > because it's limited to binding a single symbol without destructuring, > so maybe it's not such a bad idea: > > (defmacro thread-with [varname & expressions] > {:pre [(symbol? varname) (not (namespace varname))]} > `(let [~@(interleave (repeat varname) (drop-last expressions))] > ~(last expressions))) > > ;; e.g. > ;; (thread-with x 2 (+ 1 x) (/ x 2)) > ;; => 3/2 > > Having now broken the notational convention that always puts variable > bindings in a vector once, we might as well break it again by > borrowing let1 from common lisp: > > (defmacro let1 [bindable-form init-expression & body] > `(let [~bindable-form ~init-expression] > ~@body)) > > ;; e.g. > ;; (let1 x 1 (inc x)) > ;; => 2 > ;; but also supports destructuring > ;; (let1 [x y] [1 2] [y x]) > ;; => [2 1] > ;; potentially confusing to read? I've published these two macros and a few other bits as adiutores-parva on github. https://github.com/bpsm/adiutores-parva/blob/master/src/main/clojure/bpsmithmannschott/adiutores/parva.clj // Ben -- 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