Generalized Thrush Combinator added by Saeren on Fri May 31 19:50:49 2013

;;; Clojurian definition
;; (define-syntax ->
;;   (syntax-rules ()
;;     ((_ x) x)
;;     ((_ x (y z ...) rest ...)
;;      (-> (y x z ...) rest ...))))

;;; "Generalized" Thrush Combinator: The idea is that `x' can be included at any
;;; place in the following expression -- it will replace `<>', similar to its
;;; use in `cut'.
(define-syntax ->
  (syntax-rules (<>)
    ((_ x) x)
        
    ((_ x (fn <> y ...) rest ...)
     (-> (fn x y ...) rest ...))

    ((_ x (fn y <> z ...) rest ...)
     (-> (fn y x z ...) rest ...))

    ((_ x (fn y ...) rest ...)
     (-> (fn x y ...) rest ...))))


;;; These work.
(-> 2 (/ 4 <>) (expt <> 11) (* 19))
(-> 2 (/ <>) (expt <> 11) (* 19))

;;; This doesn't.
(-> 2 (/ 4 2 <>) (expt <> 11) (* 19))

;;; Question: how to replace <> anywhere in the expression?