From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Oleh Newsgroups: gmane.emacs.devel Subject: [PATCH] Clojure-like syntactic sugar for an anonymous function literal Date: Wed, 21 Jan 2015 22:38:22 +0100 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=001a1137fb78f34d5e050d305f44 X-Trace: ger.gmane.org 1421876327 9997 80.91.229.3 (21 Jan 2015 21:38:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 21 Jan 2015 21:38:47 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 21 22:38:46 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YE2z2-00032e-3v for ged-emacs-devel@m.gmane.org; Wed, 21 Jan 2015 22:38:40 +0100 Original-Received: from localhost ([::1]:50279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YE2z1-0000NE-9B for ged-emacs-devel@m.gmane.org; Wed, 21 Jan 2015 16:38:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YE2yn-0000M2-Gy for emacs-devel@gnu.org; Wed, 21 Jan 2015 16:38:26 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YE2ym-0000Um-0s for emacs-devel@gnu.org; Wed, 21 Jan 2015 16:38:25 -0500 Original-Received: from mail-wg0-x231.google.com ([2a00:1450:400c:c00::231]:60863) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YE2yl-0000Ud-Ht for emacs-devel@gnu.org; Wed, 21 Jan 2015 16:38:23 -0500 Original-Received: by mail-wg0-f49.google.com with SMTP id l18so16609244wgh.8 for ; Wed, 21 Jan 2015 13:38:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=P1/hdDq5a7uUE0sdHk6laQMdk5DNF2JXbAuqjEtuxi0=; b=m+EN3BSqJU4XKmc5uD37ryr+gO7G8Qn12xLIp/QeDaAYXWwsXYQo3ciRUZa45zRTNd vA73ECVfl7rnXiHIkQMvmn+1KQnvyiM7UYhnEEGUkHw4jhiVdKmeOE6rifN8gmcCTqMJ 0lhFGIIM4xXgY8VTDLJvofb9TlQ+d2XJa8JNyYL70kybfN/nolAOq/ucl91yCA5jBfR4 Ly1651gXN2wbQjVFS4Uek2tSim3ZjmJ3k1kqxf4Gqfwplj1UpOSAEC7woW2/RLJCbBHQ KqYuadyOjPw1uwKNwvWRI1Pk3VgSHE0qdxW2W1BAWnkhdq/abWeCHd5YwAy7kQ0rNPUb GD9A== X-Received: by 10.181.28.168 with SMTP id jp8mr49400581wid.40.1421876302842; Wed, 21 Jan 2015 13:38:22 -0800 (PST) Original-Received: by 10.27.137.137 with HTTP; Wed, 21 Jan 2015 13:38:22 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::231 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:181534 Archived-At: --001a1137fb78f34d5e050d305f44 Content-Type: text/plain; charset=UTF-8 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 --001a1137fb78f34d5e050d305f44 Content-Type: text/x-patch; charset=US-ASCII; name="0001-Modify-reader-.-is-short-lambda.patch" Content-Disposition: attachment; filename="0001-Modify-reader-.-is-short-lambda.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_i5789ple0 RnJvbSBhOGUwYzU0MTg1OTg2NTViZGZkZGE2ZDVjYjU0MTI2MmE1NTc1OTI3IE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBPbGVoIEtyZWhlbCA8b2h3b2Vvd2hvQGdtYWlsLmNvbT4KRGF0 ZTogRnJpLCA5IEphbiAyMDE1IDA4OjMzOjA3ICswMTAwClN1YmplY3Q6IFtQQVRDSF0gTW9kaWZ5 IHJlYWRlcjogIyhbXiJdLi4uKSBpcyAoc2hvcnQtbGFtYmRhIC4uLikKCiogc3JjL2xyZWFkLmMg KHJlYWQxKTogV2hlbiAiIygiIGlzIGZvdW5kLCBjaGVjayBpZiB0aGUgbmV4dCBzeW1ib2wgaXMK ICAnIicuIElmIGl0IGlzLCBjb250aW51ZSB3aXRoIHRoZSBvbGQgc3RyaW5nIHN5bn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jaDsK LQotCSAgLyogUmVhZCB0aGUgc3RyaW5nIGl0c2VsZi4gICovCi0JICB0bXAgPSByZWFkMSAocmVh ZGNoYXJmdW4sICZjaCwgMCk7Ci0JICBpZiAoY2ggIT0gMCB8fCAhU1RSSU5HUCAodG1wKSkKLQkg ICAgaW52YWxpZF9zeW50YXggKCIjIik7Ci0JICBHQ1BSTzEgKHRtcCk7Ci0JICAvKiBSZWFkIHRo ZSBpbnRlcnZhbHMgYW5kIHRoZWlyIHByb3BlcnRpZXMuICAqLwotCSAgd2hpbGUgKDEpCi0JICAg IHsKLQkgICAgICBMaXNwX09iamVjdCBiZWcsIGVuZCwgcGxpc3Q7Ci0KLQkgICAgICBiZWcgPSBy ZWFkMSAocmVhZGNoYXJmdW4sICZjaCwgMCk7Ci0JICAgICAgZW5kID0gcGxpc3QgPSBRbmlsOwot CSAgICAgIGlmIChjaCA9PSAnKScpCi0JCWJyZWFrOwotCSAgICAgIGlmIChjaCA9PSAwKQotCQll bmQgPSByZWFkMSAocmVhZGNoYXJmdW4sICZjaCwgMCk7Ci0JICAgICAgaWYgKGNoID09IDApCi0J CXBsaXN0ID0gcmVhZDEgKHJlYWRjaGFyZnVuLCAmY2gsIDApOwotCSAgICAgIGlmIChjaCkKLQkJ aW52YWxpZF9zeW50YXggKCJJbnZhbGlkIHN0cmluZyBwcm9wZXJ0eSBsaXN0Iik7Ci0JICAgICAg RnNldF90ZXh0X3Byb3BlcnRpZXMgKGJlZywgZW5kLCBwbGlzdCwgdG1wKTsKLQkgICAgfQotCSAg VU5HQ1BSTzsKLQkgIHJldHVybiB0bXA7CisgICAgICAgICAgaW50IG5leHRfY2hhciA9IFJFQURD SEFSOworICAgICAgICAgIFVOUkVBRCAobmV4dF9jaGFyKTsKKyAgICAgICAgICBpZiAobmV4dF9j aGFyID09ICciJykgeworICAgICAgICAgICAgTGlzcF9PYmplY3QgdG1wOworICAgICAgICAgICAg c3RydWN0IGdjcHJvIGdjcHJvMTsKKyAgICAgICAgICAgIGludCBjaDsKKworICAgICAgICAgICAg LyogUmVhZCB0aGUgc3RyaW5nIGl0c2VsZi4gICovCisgICAgICAgICAgICB0bXAgPSByZWFkMSAo cmVhZGNoYXJmdW4sICZjaCwgMCk7CisgICAgICAgICAgICBpZiAoY2ggIT0gMCB8fCAhU1RSSU5H UCAodG1wKSkKKyAgICAgICAgICAgICAgaW52YWxpZF9zeW50YXggKCIjIik7CisgICAgICAgICAg ICBHQ1BSTzEgKHRtcCk7CisgICAgICAgICAgICAvKiBSZWFkIHRoZSBpbnRlcnZhbHMgYW5kIHRo ZWlyIHByb3BlcnRpZXMuICAqLworICAgICAgICAgICAgd2hpbGUgKDEpCisgICAgICAgICAgICAg IHsKKyAgICAgICAgICAgICAgICBMaXNwX09iamVjdCBiZWcsIGVuZCwgcGxpc3Q7CisKKyAgICAg ICAgICAgICAgICBiZWcgPSByZWFkMSAocmVhZGNoYXJmdW4sICZjaCwgMCk7CisgICAgICAgICAg ICAgICAgZW5kID0gcGxpc3QgPSBRbmlsOworICAgICAgICAgICAgICAgIGlmIChjaCA9PSAnKScp CisgICAgICAgICAgICAgICAgICBicmVhazsKKyAgICAgICAgICAgICAgICBpZiAoY2ggPT0gMCkK KyAgICAgICAgICAgICAgICAgIGVuZCA9IHJlYWQxIChyZWFkY2hhcmZ1biwgJmNoLCAwKTsKKyAg ICAgICAgICAgICAgICBpZiAoY2ggPT0gMCkKKyAgICAgICAgICAgICAgICAgIHBsaXN0ID0gcmVh ZDEgKHJlYWRjaGFyZnVuLCAmY2gsIDApOworICAgICAgICAgICAgICAgIGlmIChjaCkKKyAgICAg ICAgICAgICAgICAgIGludmFsaWRfc3ludGF4ICgiSW52YWxpZCBzdHJpbmcgcHJvcGVydHkgbGlz dCIpOworICAgICAgICAgICAgICAgIEZzZXRfdGV4dF9wcm9wZXJ0aWVzIChiZWcsIGVuZCwgcGxp c3QsIHRtcCk7CisgICAgICAgICAgICAgIH0KKyAgICAgICAgICAgIFVOR0NQUk87CisgICAgICAg ICAgICByZXR1cm4gdG1wOworICAgICAgICAgIH0gZWxzZSB7CisgICAgICAgICAgICBVTlJFQUQo Yyk7CisgICAgICAgICAgICBMaXNwX09iamVjdCB2YWx1ZSA9IHJlYWQwIChyZWFkY2hhcmZ1bik7 CisgICAgICAgICAgICByZXR1cm4gbGlzdDIgKFFzaG9ydF9sYW1iZGEsIHZhbHVlKTsKKyAgICAg ICAgICB9CiAJfQogCiAgICAgICAvKiAjQE5VTUJFUiBpcyB1c2VkIHRvIHNraXAgTlVNQkVSIGZv bGxvd2luZyBieXRlcy4KQEAgLTQ3MzEsNiArNDczOSw3IEBAIHRoYXQgYXJlIGxvYWRlZCBiZWZv cmUgeW91ciBjdXN0b21pemF0aW9ucyBhcmUgcmVhZCEgICovKTsKICAgREVGU1lNIChRY29tbWEs ICIsIik7CiAgIERFRlNZTSAoUWNvbW1hX2F0LCAiLEAiKTsKICAgREVGU1lNIChRY29tbWFfZG90 LCAiLC4iKTsKKyAgREVGU1lNIChRc2hvcnRfbGFtYmRhLCAic2hvcnQtbGFtYmRhIik7CiAKICAg REVGU1lNIChRaW5oaWJpdF9maWxlX25hbWVfb3BlcmF0aW9uLCAiaW5oaWJpdC1maWxlLW5hbWUt b3BlcmF0aW9uIik7CiAgIERFRlNZTSAoUWFzY2lpX2NoYXJhY3RlciwgImFzY2lpLWNoYXJhY3Rl ciIpOwotLSAKMS44LjQKCg== --001a1137fb78f34d5e050d305f44--