tags:

views:

155

answers:

2

I wondering if there is a set of Emacs Lisp code that implements some of Clojure's functions. For example, -> and ->> and comp and partial, and others?

Thank you.

+2  A: 

Not sure about the others, but partial is implemented in the lexbind branch of Emacs as "curry".

technomancy
+10  A: 

I've ported the -> and ->> macros to Emacs Lisp a while ago. I use them occasionally in my configuration code and they seem to work fine.

(defmacro -> (e &rest es)
  (if (and (consp es) (not (consp (cdr es))))
      (if (consp (car es))
          `(,(caar es) ,e ,@(cdar es))
        `(,(car es) ,e))
    (if (consp es)
        `(-> (-> ,e ,(car es)) ,@(cdr es))
      e)))

(defmacro ->> (e &rest es)
  (if (and (consp es) (not (consp (cdr es))))
      (if (consp (car es))
          `(,@(car es) ,e)
        `(,(car es) ,e))
    (if (consp es)
        `(->> (->> ,e ,(car es)) ,@(cdr es))
      e)))
Michał Marczyk