From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Oleh Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Clojure-like syntactic sugar for an anonymous function literal Date: Thu, 22 Jan 2015 11:40:40 +0100 Message-ID: References: <54C05269.7050602@dancol.org> <87oaprfa3t.fsf@fencepost.gnu.org> <877fwfunnz.fsf@uwakimon.sk.tsukuba.ac.jp> <871tmnf6lj.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1421923261 11256 80.91.229.3 (22 Jan 2015 10:41:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 22 Jan 2015 10:41:01 +0000 (UTC) Cc: "Stephen J. Turnbull" , "emacs-devel@gnu.org" To: David Kastrup Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 22 11:41:01 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 1YEFC7-00054V-NO for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2015 11:40:59 +0100 Original-Received: from localhost ([::1]:52198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEFC7-000707-4U for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2015 05:40:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEFBt-0006zn-9J for emacs-devel@gnu.org; Thu, 22 Jan 2015 05:40:46 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEFBs-0001ku-81 for emacs-devel@gnu.org; Thu, 22 Jan 2015 05:40:45 -0500 Original-Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:62508) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEFBp-0001k3-AY; Thu, 22 Jan 2015 05:40:41 -0500 Original-Received: by mail-wi0-f169.google.com with SMTP id bs8so39305134wib.0; Thu, 22 Jan 2015 02:40:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=SfEnBdeAd7RSKfq8lTn3UgruJGaggH8xqbGvgLx12SA=; b=sqOX7kH1mGunVi2qttY6Wy0XSPp95jeqCm4bWNOMLrNb2QdtPEj5ZIgotp1nRBAugm 65cFAAvzrhzkvhz4m7geearUp2EQ53BMheqr+ofaIjkN7Ka2NnUjjPXJyYOILszPoddf Q/XoM2p4k1617i4rjU3mF0umC3GpjIeEZ3C+nL7QWQrngWvYGAXxIchgirNrQoFT6Rgb gtyirRLUbHq5ERC++HWbk9lia0AD4Z95LsvpXPpYKyomXVNpukOVBhkX5AaPhF2odZes Ry2B8IweAnLcbgbdzTNtsvToy9TYbqYekCeb/yFykzvctPeSFeMBEJZ0ZsOnUWrLWLmF STmQ== X-Received: by 10.180.74.236 with SMTP id x12mr66871100wiv.40.1421923240501; Thu, 22 Jan 2015 02:40:40 -0800 (PST) Original-Received: by 10.27.137.137 with HTTP; Thu, 22 Jan 2015 02:40:40 -0800 (PST) In-Reply-To: <871tmnf6lj.fsf@fencepost.gnu.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::229 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:181582 Archived-At: >>> > 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. If it were up to me, I'd use `cl-loop' everywhere. But I'm not in a vacuum: I use and monitor many packages. And I can't just tell 60 random people: "Dont use `dash', that approach is silly, use `cl-loop' instead". What I can do though, is to provide an alternative for core Emacs with no disadvantages of the anaphoric macros of `dash'.