From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Oleh Krehel 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 19:26:29 +0200 Message-ID: <87oalh6blm.fsf@gmail.com> References: <87egmdncf7.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1431970370 12304 80.91.229.3 (18 May 2015 17:32:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 May 2015 17:32:50 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 18 19:32: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 1YuOuC-0002j3-CO for ged-emacs-devel@m.gmane.org; Mon, 18 May 2015 19:32:44 +0200 Original-Received: from localhost ([::1]:42298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuOuB-0001Ff-Je for ged-emacs-devel@m.gmane.org; Mon, 18 May 2015 13:32:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuOu7-0001Fa-Uh for emacs-devel@gnu.org; Mon, 18 May 2015 13:32:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YuOu4-0003OK-Op for emacs-devel@gnu.org; Mon, 18 May 2015 13:32:39 -0400 Original-Received: from mail-wi0-x241.google.com ([2a00:1450:400c:c05::241]:35582) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YuOu4-0003OE-Ho for emacs-devel@gnu.org; Mon, 18 May 2015 13:32:36 -0400 Original-Received: by wibbw19 with SMTP id bw19so1440252wib.2 for ; Mon, 18 May 2015 10:32:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=rQ0MHfuhLlo2PnNHE61h/TbKBfdqFqIR9/n6Pk/KBxg=; b=xe627IxbVK8pl9h5Jes5ABjo/ZIAqH4C6iLdWPwkoIL02EneQDVzS0uzC74d42sWjv mb3TmYjszl93R5bNPJCuG9POJjVPyqLxgiZEY8sfz/X2ytwbEY5IeLcXPfUKRLWT9aME 18vc6js/6WLYvD6B7oaGt98HBLPPY1+zGSsAKQZnMkeySb8OSATj7ojq08fGABQ9R90G 3Q454xusFUGXl7m51UJYFefW8BXFOTaBryBBodInD6haDJOKNa+wXSWYNBZ+keN33826 a62w+ZGUTBHYWGhNhA2rOw6FFxw4YrC98oBGRv4PMLlsZo/ijGW8S7uJws4cKNrRLJje KFug== X-Received: by 10.180.8.98 with SMTP id q2mr19955527wia.53.1431970355859; Mon, 18 May 2015 10:32:35 -0700 (PDT) Original-Received: from firefly (dyn069045.nbw.tue.nl. [131.155.69.45]) by mx.google.com with ESMTPSA id mc20sm13426426wic.15.2015.05.18.10.32.35 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 18 May 2015 10:32:35 -0700 (PDT) In-Reply-To: (Stefan Monnier's message of "Mon, 18 May 2015 12:39:57 -0400") 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: 2a00:1450:400c:c05::241 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:186591 Archived-At: Stefan Monnier writes: >> (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. I wrote this: (defmacro let-when-compile (bindings &rest body) "Like `let', but allows for compile time optimization. \n(fn BINDINGS BODY)" (declare (indent 1) (debug let)) `(progv ',(mapcar #'car bindings) ',(mapcar (lambda (x) (eval (cadr x))) bindings) ,@body)) It sort of works (evals to the correct thing, and the byte code looks OK), but I get a lot of byte compiler warnings. And I don't see while `progv' should expand to a `while' loop. Anyway, here's an example: (let-when-compile ((foo (+ 2 2))) (defvar bar (+ foo foo))) And here's the expansion, after I've evaluated the while loop: (eval (let ((foo (quote 4))) (funcall (quote (lambda nil (defvar bar (+ foo foo))))))) On the other hand, using `let-opt': (let-opt ((foo (+ 2 2))) (defvar bar (opt (+ foo foo)))) expands to this: (defvar bar '8) Which I think could be valuable while refactoring. Oleh