;;; Threading macros ;;; ;;; `->' passes a value through a chain of forms, each step taking what ;;; came before it as its first argument, so a chain of calls reads in ;;; the order it happens rather than inside out. Clojure spells it this ;;; way and this is the same thing: ;;; ;;; (-> 5 double-it (add 3)) == (add (double-it 5) 3) ;;; ;;; A step that is not a list is a call of one argument, so `(-> x f)' ;;; is `(f x)' and a method is a step like any other. (pub defmacro (-> x . steps) (let thread ((acc x) (steps steps)) (if (null? steps) acc (thread (if (pair? (car steps)) (cons (car (car steps)) (cons acc (cdr (car steps)))) (list (car steps) acc)) (cdr steps)))))