From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Clojure-like syntactic sugar for an anonymous function literal Date: Thu, 22 Jan 2015 11:32:56 +0100 Message-ID: <871tmnf6lj.fsf@fencepost.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 1421922798 3980 80.91.229.3 (22 Jan 2015 10:33:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 Jan 2015 10:33:18 +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:33:14 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 1YEF4b-0000Xi-RL for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2015 11:33:13 +0100 Original-Received: from localhost ([::1]:52183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEF4a-0005Pc-Or for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2015 05:33:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEF4N-0005PW-Qk for emacs-devel@gnu.org; Thu, 22 Jan 2015 05:33:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEF4N-00072p-1c for emacs-devel@gnu.org; Thu, 22 Jan 2015 05:32:59 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEF4M-00072g-UI for emacs-devel@gnu.org; Thu, 22 Jan 2015 05:32:58 -0500 Original-Received: from localhost ([127.0.0.1]:58948 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEF4L-0002NQ-1E; Thu, 22 Jan 2015 05:32:57 -0500 Original-Received: by lola (Postfix, from userid 1000) id 6F2D5DF3F4; Thu, 22 Jan 2015 11:32:56 +0100 (CET) In-Reply-To: (Oleh's message of "Thu, 22 Jan 2015 11:22:42 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e 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:181581 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. > > On the other hand, `mapcar' is a C function. It and all other > functions can use `short-lambda' instead of being reimplemented as > macros on a case-per-case basis by `dash'. So use cl-loop. Has the advantage of being _both_ concise as well as efficient after compilation since Emacs Lisp is not really fast at function calls. (cl-loop for i from 1 to 3 collect (* i i)) Or (cl-loop for i in '(1 2 3) collect (* i i)) The code cl-loop creates is usually quite faster than any of the map* functions. I haven't checked with lexical bindings though: it is conceivable that the anonymous lambda cost goes down for them, but so does the variable-binding cost for cl-loop. -- David Kastrup