From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Clojure-like syntactic sugar for an anonymous function literal Date: Thu, 22 Jan 2015 11:56:22 +0100 Message-ID: <877fwfgk2x.fsf@gnu.org> References: <54C05269.7050602@dancol.org> <87oaprfa3t.fsf@fencepost.gnu.org> <877fwfunnz.fsf@uwakimon.sk.tsukuba.ac.jp> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1421924213 27429 80.91.229.3 (22 Jan 2015 10:56:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 Jan 2015 10:56:53 +0000 (UTC) Cc: "Stephen J. Turnbull" , "emacs-devel@gnu.org" To: Oleh Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 22 11:56:48 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 1YEFRN-0005jy-6s for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2015 11:56:45 +0100 Original-Received: from localhost ([::1]:52254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEFRM-0002M8-HQ for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2015 05:56:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEFR8-0002L4-5X for emacs-devel@gnu.org; Thu, 22 Jan 2015 05:56:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEFR3-0006zg-5u for emacs-devel@gnu.org; Thu, 22 Jan 2015 05:56:30 -0500 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:52219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEFR3-0006zP-02 for emacs-devel@gnu.org; Thu, 22 Jan 2015 05:56:25 -0500 Original-Received: from thinkpad-t440p (dhcp08.uni-koblenz.de [141.26.71.8]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by deliver.uni-koblenz.de (Postfix) with ESMTPSA id 3B59F1A848E; Thu, 22 Jan 2015 11:56:24 +0100 (CET) Mail-Followup-To: Oleh , "Stephen J. Turnbull" , "emacs-devel\@gnu.org" In-Reply-To: (Oleh's message of "Thu, 22 Jan 2015 11:22:42 +0100") User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 141.26.64.15 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:181583 Archived-At: Oleh writes: >> > The most popular library in MELPA, https://github.com/magnars/dash.el, >> > implements it (for a long time) like this: >> > >> > (--map (* it it) '(1 2 3)) >> > ;; => (1 4 9) >> > >> > With my approach, it's: >> > >> > (mapcar #(* % %) '(1 2 3)) >> > ;; => (1 4 9) >> >> That looks almost like Perl! Now I'm -2. Just require dash. > > How is `dash' better? `--map' is a macro: > > (defmacro --map (form list) > "Anaphoric form of `-map'." > (declare (debug (form form))) > `(mapcar (lambda (it) ,form) ,list)) > > `dash' also gives other ~40 macros that look like this, littered all > over the code in the MELPA, so it's impossible to go on without > understanding what `dash' does. FWIW, I favor your Clojure-like syntax over anaphoric macros. And one benefit is that you're not restricted to one list to map over as in --map. E.g., your approach works out of the box with (cl-mapcar #(- %5 %4 %3 %2 %1) list1 list2 list3 list4 list5) for which there is no dash equivalent. Of course, --map could be extended to create args (it1 ... itN) if more than one list is given. BTW, do you also support %& to declare that the lambda has a &rest arg so that you can do (apply #'cl-mapcar #(apply #'- (reverse %&)) list-of-lists) ? So basically I like that syntax (or maybe #l(...) or #fn(...)) and would consider using it where it makes sense. But as others already mentioned, those places are much fewer than in an almost purely functional language like Clojure. Bye, Tassilo