(or emacs irrelevant)

Adding a bit of Clojure's sugar to Elisp

I just wanted to highlight my latest submission to emacs-devel.

The patch

The attached patch, together with the macro short-lambda will add a shorthand for defining lambdas in Emacs Lisp.

Here's an excerpt from the Clojure reader docs

Anonymous function literal (#())

#(...) => (fn [args] (...))

where args are determined by the presence of argument literals taking the form %, %n or %&. % is a synonym for %1, %n designates the nth arg (1-based), and %& designates a rest arg. This is not a replacement for fn - idiomatic used would be for very short one-off mapping/filter fns and the like.

#() forms cannot be nested.

What the patch does

It makes it possible to write this in Elisp:

(mapc #(put % 'disabled nil)
      '(upcase-region downcase-region narrow-to-region))

You can also do this and other things that you would expect, if you're familiar with Clojure:

(cl-mapcar #(concat %1 " are " %2)
           '("roses" "violets")
           '("red" "blue"))
;; => ("roses are red" "violets are blue")

Or you could replace this snippet from org-mode's code:

(mapcar (lambda (x)
          (and (member (car x) matchers) (nth 1 x)))

with this sugar-coated code:

(mapcar #(and (member (car %) matchers) (nth 1 %))


I hope that this gets accepted, although there are some conservative people that protest against this change. Let me know if you would like to have this option for your Elisp setups. And remember that you can try out the patch if you're familiar with building Emacs from source.