From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Use the new let-opt macro in place of pcase-let in lisp-mode.el Date: Mon, 18 May 2015 12:39:57 -0400 Message-ID: References: <87egmdncf7.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1431967235 23011 80.91.229.3 (18 May 2015 16:40:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 May 2015 16:40:35 +0000 (UTC) Cc: emacs-devel@gnu.org To: Oleh Krehel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 18 18:40:26 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 1YuO5W-0001dY-GR for ged-emacs-devel@m.gmane.org; Mon, 18 May 2015 18:40:22 +0200 Original-Received: from localhost ([::1]:42071 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuO5V-0000a8-SM for ged-emacs-devel@m.gmane.org; Mon, 18 May 2015 12:40:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuO5C-0000WE-MJ for emacs-devel@gnu.org; Mon, 18 May 2015 12:40:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuO58-0005O9-Ox for emacs-devel@gnu.org; Mon, 18 May 2015 12:40:02 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:32762) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuO58-0005Nx-L1 for emacs-devel@gnu.org; Mon, 18 May 2015 12:39:58 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgUFAGvvdVTO+LMW/2dsb2JhbAA3gVOhb4EIgXUBAQQBViMFCwsOJhIUGA0kiBOiEYwbVQODPgMDC4NiBKNjhFg X-IPAS-Result: AgUFAGvvdVTO+LMW/2dsb2JhbAA3gVOhb4EIgXUBAQQBViMFCwsOJhIUGA0kiBOiEYwbVQODPgMDC4NiBKNjhFg X-IronPort-AV: E=Sophos;i="5.11,557,1422939600"; d="scan'208";a="120617460" Original-Received: from 206-248-179-22.dsl.teksavvy.com (HELO fmsmemgm.homelinux.net) ([206.248.179.22]) by ironport2-out.teksavvy.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 18 May 2015 12:39:57 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id 51F8AAE164; Mon, 18 May 2015 12:39:57 -0400 (EDT) In-Reply-To: <87egmdncf7.fsf@gmail.com> (Oleh Krehel's message of "Mon, 18 May 2015 17:16:44 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:186587 Archived-At: > As I understood, all this hassle is for not having to call `regexp-opt' > at run-time, but instead at compile-time. That's right (and it's particularly important here since this file is preloaded, so calling it at runtime would require preloading regexp-opt as well). > For your consideration, I add a new macro named `let-opt' that is more > efficient (I assume, `macroexpand' doesn't work properly for > `pcase-let') than `pcase-let' in this case, and also much more simple > and straightforward. For this particular case, I think efficiency is of no importance, really. And in their more general uses, these two macros are fairly unrelated. > (defmacro let-opt (bindings &rest body) > "Like `let', but allows for compile time optimization. > Expressions wrapped with `opt' will be subsituted for their values. > \n(fn BINDINGS BODY)" > (declare (indent 1) (debug let)) > (let ((bnd (mapcar (lambda (x) (cons (car x) (eval (cadr x)))) > bindings))) > `(cl-macrolet ((opt (&rest body) > (list 'quote (eval (cons 'progn body) ',bnd)))) > ,@body))) I think I like this idea of "compile-time-only let-binding". But I don't like this `opt' thingy very much and I think we can get rid of it if we use dynamic-scoping instead. IOW, define a let-when-compile macro which uses progv to setup the bindings and then calls `macroexpand-all' on the body. The body's `eval-when-compile' can then use those vars just fine. Stefan