all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: "Like `let*' but ....."
Date: Fri, 27 Jan 2017 20:31:13 +0000	[thread overview]
Message-ID: <20170127203113.GA2630@acm> (raw)
In-Reply-To: <jwv7f5jzr7u.fsf-monnier+gmane.emacs.devel@gnu.org>

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 #<subr ...> object or god knows what else.


>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).



      reply	other threads:[~2017-01-27 20:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-24 21:12 "Like `let*' but ....." Alan Mackenzie
2017-01-24 21:26 ` Clément Pit-Claudel
2017-01-27 20:33   ` Alan Mackenzie
2017-01-24 23:10 ` Michael Heerdegen
2017-01-25  5:08   ` Stefan Monnier
2017-01-27 20:31     ` Alan Mackenzie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170127203113.GA2630@acm \
    --to=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.