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.
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)))
You should definitely take a look at dash.el . It provides a lot of Clojure-inspired functions like:
(fn list)
(fn initial-value list)
(fn initial-value list)
(fn list)
(fn list)
(pred list)
(pred list)
(fn list)
(pred rep list)
(fn list)
(l)
(&rest lists)
(fn list)
(&rest args)
(pred list)
(pred list)
(pred list)
(pred list)
(pred list)
(list fn)
(list pred fn)
(num fn)
(nx)
(list from &optional to)
(n list)
(n list)
(pred list)
(pred list)
(n list)
(nx list)
(pred list)
(pred list)
(n list)
(n step list)
(n step list)
(n list)
(fn list)
(fn list)
(fn list)
(sep list)
(&rest lists)
(fn list1 list2)
(list1 list2)
(pred list)
(pred list)
(list list2)
(list list2)
(list list2)
(list)
(list element)
(predicate list)
(fn &rest args)
(fn &rest args)
(fn)
(x &optional form &rest more)
(x form &rest more)
(x form &rest more)
(var-val &rest body)
(vars-vals &rest body)
(var-val then &optional else)
(vars-vals then &optional else)
(car cdr)
(list)
I find this library extremely useful.
不确定其他人,但部分是在Emacs的lexbind分支中实现为“咖喱”。
I've written these macros recently. They're not recursive and are less verbose. But I haven't tested them extensively yet.
(defmacro ->> (x &rest forms)
(while forms
(setq x (append (pop forms) (list x))))
x)
(defmacro -> (x &rest forms)
(while forms
(let ((form (pop forms)))
(push x (cdr form))
(setq x form)))
x)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.