[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Clojure-like syntactic sugar for an anonymous function literal
From: |
Oleh |
Subject: |
[PATCH] Clojure-like syntactic sugar for an anonymous function literal |
Date: |
Wed, 21 Jan 2015 22:38:22 +0100 |
Hi all,
This is my first attempt of modifying the C source of Emacs.
The goal is to add a new reader syntax:
#(foo bar) should translate to (short-lambda (foo bar))
This is in the same way that the `backquote' is working now:
`(foo bar) translates to (backquote (foo bar))
The `short-lambda' macro is implemented here:
https://github.com/abo-abo/short-lambda.
In the simplest form, i.e. one that does not allow multiple or
&rest-style arguments, it can look like this:
(defmacro short-lambda (x)
`(lambda (%) ,x))
Even in this simple form, it can sweeten up Elisp a lot:
(mapc #(put % 'disabled nil)
'(upcase-region downcase-region narrow-to-region))
With the (less trivial) linked `short-lambda', the following is
possible:
(cl-mapcar #(concat %1 " are " %2)
'("roses" "violets")
'("red" "blue"))
Here's a snippet from `org-mode':
(mapcar (lambda (x)
(and (member (car x) matchers) (nth 1 x)))
org-latex-regexps)
Here's the sweetened code:
(mapcar #(and (member (car %) matchers) (nth 1 %))
org-latex-regexps)
As far as I know, only #("foo" ...) literal is already taken, so #(Z,
where Z is anything but a " is up for grabs, reader-wise.
I hope that you don't view this patch as malarkey. Saving a few chars
while typing and reading is a big deal to a lot of people. And the
way I see it, this implementation doesn't cost much.
regards,
Oleh
0001-Modify-reader-.-is-short-lambda.patch
Description: Text Data
- [PATCH] Clojure-like syntactic sugar for an anonymous function literal,
Oleh <=
Re: [PATCH] Clojure-like syntactic sugar for an anonymous function literal, Daniel Colascione, 2015/01/21