From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: "Like `let*' but ....." Date: Fri, 27 Jan 2017 20:31:13 +0000 Message-ID: <20170127203113.GA2630@acm> References: <20170124211227.GC7358@acm> <87lgu0qcks.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1485549177 28859 195.159.176.226 (27 Jan 2017 20:32:57 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 27 Jan 2017 20:32:57 +0000 (UTC) User-Agent: Mutt/1.7.2 (2016-11-26) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 27 21:32:49 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cXDCP-0006Tg-Rw for ged-emacs-devel@m.gmane.org; Fri, 27 Jan 2017 21:32:45 +0100 Original-Received: from localhost ([::1]:48795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXDCV-0001O1-7U for ged-emacs-devel@m.gmane.org; Fri, 27 Jan 2017 15:32:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cXDBJ-0001KI-Vc for emacs-devel@gnu.org; Fri, 27 Jan 2017 15:31:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cXDBE-0002MY-Vg for emacs-devel@gnu.org; Fri, 27 Jan 2017 15:31:38 -0500 Original-Received: from ocolin.muc.de ([193.149.48.4]:28294 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1cXDBE-0002LM-MJ for emacs-devel@gnu.org; Fri, 27 Jan 2017 15:31:32 -0500 Original-Received: (qmail 57630 invoked by uid 3782); 27 Jan 2017 20:31:30 -0000 Original-Received: from acm.muc.de (p548C733D.dip0.t-ipconnect.de [84.140.115.61]) by colin.muc.de (tmda-ofmipd) with ESMTP; Fri, 27 Jan 2017 21:31:29 +0100 Original-Received: (qmail 27899 invoked by uid 1000); 27 Jan 2017 20:31:13 -0000 Content-Disposition: inline In-Reply-To: X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 193.149.48.4 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:211659 Archived-At: Hello, Stefan. On Wed, Jan 25, 2017 at 00:08:01 -0500, Stefan Monnier wrote: [ .... ] > BTW, regarding the big pcase-let* in byte-compile-file-form-defalias, > it was partly an experiment in the use of pcase patterns. > OT1H I'm not convinced the result speaks very much in favor of pcase, > OTOH if you try to rewrite this code without pcase it's not > pretty either. > I'll read it for you: > ;; `macro' is non-nil if it defines a macro. > ;; `fun' is the function part of `arg' (defaults to `arg'). > (((or (and (or `(cons 'macro ,fun) `'(macro . ,fun)) (let macro t)) > (and (let fun arg) (let macro nil))) > arg) > This part binds two vars: `fun` and `macro`. > Basically, it binds `fun` to the value of `arg` except that if `arg` is > a "macro value", `fun` gets the value of the macro's function (and > `macro` gets value t rather than nil). OK, I think I might have got the semantics now. The `arg' at the end of that thing is the object upon which the pcase pattern at the beginning of it acts on. The `or's and `and's are pcase ones, not the primitives. The variables which are bound are precisely the cadrs of the three element lists beginning `(let ...)', none of the variables bound in the pcase form surviving after that form terminates. Er, actually that isn't true, looking at `lam' in the next bit. Variables bound within the pcase pattern remain bound over the entire pcase-let* form (unless, of course, a subsequent binding rebinds the same symbol). Am I right? > ;; `lam' is the lambda expression in `fun' (or nil if not > ;; recognized). > ((or `(,(or `quote `function) ,lam) (let lam nil)) > fun) > This only binds `lam`. It takes the `fun` apart and extracts a lambda > expression from it (or nil if it can't). > ;; `arglist' is the list of arguments (or t if not recognized). > ;; `body' is the body of `lam' (or t if not recognized). > ((or `(lambda ,arglist . ,body) > ;; `(closure ,_ ,arglist . ,body) > (and `(internal-make-closure ,arglist . ,_) (let body t)) > (and (let arglist t) (let body t))) > lam)) > This tries to take apart `lam` and extract two parts: `arglist` and `body`. > The complexity here is that `arg` doesn't hold a "macro value" > (i.e. something of the form (macro . FUN)), but instead it holds an > expression that will return a macro value. So `arg` can be of the form > (quote (macro . FUN)) > (cons 'macro 'FUN) > (cons 'macro #'FUN) > (cons 'macro (internal-make-closure ...)) > ... > and of course FUN is usually of the form (lambda ...) but it can also be > a plain symbol, or a # object or god knows what else. > Stefan -- Alan Mackenzie (Nuremberg, Germany).