all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Oleh Krehel <ohwoeowho@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: emacs-devel@gnu.org
Subject: Re: Question on pcase
Date: Fri, 23 Oct 2015 15:26:32 +0200	[thread overview]
Message-ID: <87k2qdd8c7.fsf@gmail.com> (raw)
In-Reply-To: <87wpud68e6.fsf@web.de> (Michael Heerdegen's message of "Fri, 23 Oct 2015 15:07:13 +0200")

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Oleh Krehel <ohwoeowho@gmail.com> writes:
>
>> Thanks Michael, that's almost exactly what I need. The only thing is
>> that I don't understand what `-bind-' is.
>
> That's just a placeholder I used.  Depending on what pcase form you are
> using (`pcase', `pcase-lambda', `pcase-let'), the semantic is a bit
> different.
>
> You can just imagine that it creates a local binding, like `let', and
> that binding is available in the CODE part of the
>
>   (PATTERN CODE...)
>
> of this branch.
>
> The actual code `pcase' produces is easy as well but longer; when I
> included this aspect in `pcase-demystify-pattern', the result would look
> more like what you would get with `macroexpand', so I don't think it
> would be useful, since the semantic is also slightly different in other
> `pcase' derived macros.

I think there's a bit of miscommunication here. I can `macroexpand' as
well, but the branch info isn't clear-cut in that case.  The thing is
that I don't want to use `pcase-demystify-pattern' to understand
approximately what each pattern does, I want it to expand to the exact
code that is run for a branch, and I want to run that code.

This can all be done in-place without producing extra buffers. A simple
"C-c C-e" on a branch should either:

    (message "the branch doesn't match")

or e.g.:

    (progn
      (setq hookfun (car res))
      (setq start (nth 0 (cdr res)))
      (setq end (nth 1 (cdr res)))
      (setq collection (nth 2 (cdr res)))
      (setq plist (nthcdr 3 (cdr res)))
      (message "match"))

Instead, (pcase-demystify-pattern '`(,hookfun . (,start ,end ,collection . ,plist)))
gives:

    (if (consp -tested-expression-)
        (let* ((x (car -tested-expression-))
               (x (cdr -tested-expression-)))
          (if (consp x)
              (let* ((x (car x))
                     (x (cdr x)))
                (if (consp x)
                    (let* ((x (car x))
                           (x (cdr x)))
                      (if (consp x)
                          (let* ((x (car x))
                                 (x (cdr x)))
                            (progn
                              (-bind- plist x)
                              (-bind- collection x)
                              (-bind- end x)
                              (-bind- start x)
                              (-bind- hookfun x)))
                        nil))
                  nil))
            nil))
      nil)

Which is indeed close to what I need. I guess `-bind-` should be some
macro that pops and does a `set'. I'm just not sure that this is exactly
true, and will work for all patterns.



  reply	other threads:[~2015-10-23 13:26 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-22 14:46 Question on pcase Oleh Krehel
2015-10-22 21:19 ` Michael Heerdegen
2015-10-23  6:30   ` Eli Zaretskii
2015-10-23 11:58     ` Oleh Krehel
2015-10-23 12:23       ` Michael Heerdegen
2015-10-23 12:42         ` Oleh Krehel
2015-10-23 13:07           ` Michael Heerdegen
2015-10-23 13:26             ` Oleh Krehel [this message]
2015-10-23 13:59               ` Michael Heerdegen
2015-10-27 23:50                 ` Johan Bockgård
2015-10-30  1:33                   ` Michael Heerdegen
2015-10-23 14:23               ` Michael Heerdegen
2015-10-23 12:17     ` Michael Heerdegen
2015-10-23 12:22       ` Oleh Krehel
2015-10-23 13:26       ` Eli Zaretskii
2015-10-23 14:14         ` Michael Heerdegen
2015-10-23 14:41           ` Eli Zaretskii
2015-10-23 18:38             ` Michael Heerdegen
2015-10-23 18:43               ` Eli Zaretskii
2015-10-23 19:59               ` Przemysław Wojnowski
2015-10-23 21:01                 ` Michael Heerdegen
2015-10-23 20:23               ` Przemysław Wojnowski
2015-10-23 20:39                 ` Michael Heerdegen
2015-10-24 11:37                   ` Przemysław Wojnowski
2015-10-24  9:01               ` Alan Mackenzie
2015-10-24 12:58                 ` Stephen Berman
2015-10-24 17:47                   ` Alan Mackenzie
2015-10-24 19:10                     ` Stephen Berman
2015-10-24 19:28                       ` Alan Mackenzie
2015-10-25  0:00                         ` pcase docstring tweaks (was: Question on pcase) Michael Heerdegen
2015-10-27 14:54                           ` pcase docstring tweaks Michael Heerdegen
2015-10-27 18:57                             ` Stefan Monnier
2015-10-27 20:14                               ` Michael Heerdegen
2015-10-28  3:15                             ` Richard Stallman
2015-10-28 17:08                               ` Michael Heerdegen
2015-10-24 17:00                 ` Question on pcase Drew Adams
2015-10-24 17:22                   ` Alan Mackenzie
2015-10-24 17:36                     ` Drew Adams
2015-10-24 20:03                     ` Johan Bockgård
2015-10-24 23:11                       ` Michael Heerdegen
2015-10-26 15:55               ` Oleh Krehel
2015-10-26 16:07                 ` Michael Heerdegen
2015-10-27  8:42                   ` Oleh Krehel
2015-10-26 16:20                 ` Michael Heerdegen
2015-10-27  8:42                   ` Oleh Krehel
2015-10-27 14:27                     ` Michael Heerdegen
2015-10-27 14:47                       ` Michael Heerdegen
2015-10-28 18:05                         ` Michael Heerdegen
2015-10-29  9:44                           ` Oleh Krehel
2015-10-30  1:11                             ` Michael Heerdegen
2015-10-26 16:35                 ` Andreas Schwab

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=87k2qdd8c7.fsf@gmail.com \
    --to=ohwoeowho@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=michael_heerdegen@web.de \
    /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.