[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question on pcase
From: |
Oleh Krehel |
Subject: |
Re: Question on pcase |
Date: |
Fri, 23 Oct 2015 15:26:32 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
Michael Heerdegen <address@hidden> writes:
> Oleh Krehel <address@hidden> 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.
- Question on pcase, Oleh Krehel, 2015/10/22
- Re: Question on pcase, Michael Heerdegen, 2015/10/22
- Re: Question on pcase, Eli Zaretskii, 2015/10/23
- Re: Question on pcase, Oleh Krehel, 2015/10/23
- Re: Question on pcase, Michael Heerdegen, 2015/10/23
- Re: Question on pcase, Oleh Krehel, 2015/10/23
- Re: Question on pcase, Michael Heerdegen, 2015/10/23
- Re: Question on pcase,
Oleh Krehel <=
- Re: Question on pcase, Michael Heerdegen, 2015/10/23
- Re: Question on pcase, Johan Bockgård, 2015/10/27
- Re: Question on pcase, Michael Heerdegen, 2015/10/29
- Re: Question on pcase, Michael Heerdegen, 2015/10/23
- Re: Question on pcase, Michael Heerdegen, 2015/10/23
- Re: Question on pcase, Oleh Krehel, 2015/10/23
- Re: Question on pcase, Eli Zaretskii, 2015/10/23
- Re: Question on pcase, Michael Heerdegen, 2015/10/23
- Re: Question on pcase, Eli Zaretskii, 2015/10/23
- Re: Question on pcase, Michael Heerdegen, 2015/10/23