emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question on pcase


From: Michael Heerdegen
Subject: Re: Question on pcase
Date: Fri, 23 Oct 2015 15:59:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Oleh Krehel <address@hidden> writes:

> 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"))

That doesn't make sense to me.  In real-life code, you have free
variables, and whether a branch matches depends on the current
environment.  E.g. if you have

(pcase x
 (1 t)
 (_ nil))

and you put the cursor after the "1" pattern and hit C-c C-e, what would
you expect to happen?  Whether that branch matches depends on the
current binding of x.

> 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)

The Lisp printer discarded relevant information here, please do

(setq print-gensym t)
(setq print-circle t)

when printing a result of `pcase-demystify-pattern'.  After you have
done that, you exactly see how matching is done.

> 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.

The only thing that makes sense to me would be to make `edebug' let you
step into a pattern.  AFAICT that would be a very hard work.


Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]