[英]Clojure functions for Emacs?
I wondering if there is a set of Emacs Lisp code that implements some of Clojure's functions. 我想知道是否有一组Emacs Lisp代码实现了一些Clojure的功能。 For example, -> and ->> and comp and partial, and others? 例如, - >和 - >>和comp和partial,以及其他?
Thank you. 谢谢。
I've ported the ->
and ->>
macros to Emacs Lisp a while ago. 我刚才将->
和->>
宏移植到了Emacs Lisp。 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 . 你一定要看看dash.el。 It provides a lot of Clojure-inspired functions like: 它提供了许多Clojure灵感的功能,如:
(fn list)
-map (fn list)
(fn initial-value list)
-reduce-from (fn initial-value list)
(fn initial-value list)
-reduce-r-from (fn initial-value list)
(fn list)
-reduce (fn list)
(fn list)
-reduce-r (fn list)
(pred list)
-filter (pred list)
(pred list)
- 删除(pred list)
(fn list)
-keep (fn list)
(pred rep list)
-map-when (pred rep list)
(fn list)
-map-indexed (fn list)
(l)
-flatten (l)
(&rest lists)
-concat (&rest lists)
(fn list)
-mapcat (fn list)
(&rest args)
-cons * (&rest args)
(pred list)
-count (pred list)
(pred list)
(pred list)
(pred list)
(pred list)
(list fn)
-each (list fn)
(list pred fn)
-each-while (list pred fn)
(num fn)
-dotimes (num fn)
(nx)
-repeat (nx)
(list from &optional to)
-slice (list from &optional to)
(n list)
-take (n list)
(n list)
-drop (n list)
(pred list)
-take-while (pred list)
(pred list)
-drop-while (pred list)
(n list)
-split-at (n list)
(nx list)
-insert-at (nx list)
(pred list)
-split-with (pred list)
(pred list)
- 分离(pred list)
(n list)
- 分区(n list)
(n step list)
-partition-all-in-steps (n step list)
(n step list)
- 分步(n step list)
(n list)
-partition-all (n list)
(fn list)
-partition-by (fn list)
(fn list)
-partition-by-header (fn list)
(fn list)
-group-by (fn list)
(sep list)
-interpose (sep list)
(&rest lists)
-interleave (&rest lists)
(fn list1 list2)
-zip-with (fn list1 list2)
(list1 list2)
-zip (list1 list2)
(pred list)
- 第一个(pred list)
(pred list)
-last (pred list)
(list list2)
-union (list list2)
(list list2)
-difference (list list2)
(list list2)
-intersection (list list2)
(list)
-distinct (list)
(list element)
(predicate list)
-sort (predicate list)
(fn &rest args)
-partial (fn &rest args)
(fn &rest args)
-rpartial (fn &rest args)
(fn)
-applify (fn)
(x &optional form &rest more)
- > (x &optional form &rest more)
(x form &rest more)
- >> (x form &rest more)
(x form &rest more)
- > (x form &rest more)
(var-val &rest body)
-when-let (var-val &rest body)
(vars-vals &rest body)
-when-let * (vars-vals &rest body)
(var-val then &optional else)
-if-let (var-val then &optional else)
(vars-vals then &optional else)
-if-let * (vars-vals then &optional else)
(car cdr)
!cons (car cdr)
(list)
!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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.