all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: pcase-memoize: equal first branch, yet different
Date: Mon, 04 Mar 2013 14:33:41 -0500	[thread overview]
Message-ID: <jwvlia3as3p.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87hakv6tek.fsf@web.de> (Michael Heerdegen's message of "Fri, 01 Mar 2013 16:17:55 +0100")

> I get a not so useful message using `pcase' in the following scenario
> using trunk:
[...]
>                          `(lambda (_event)
>                             (interactive "e")
>                             (pcase ,flag
>                               (`"-" (dired-sort-menu-set-switches ""))
>                               ((or `"t" `"S")
>                                (dired-sort-menu-set-switches ,flag))
>                               (`"r"
>                               (dired-sort-menu-toggle-reverse)))))))
[...]
> This works well, but every time I click on a flag, I get this message:
> | pcase-memoize: equal first branch, yet different
> What does that mean?  It's annoying.

The pcase macro's expansion can take a significant amount of time to
generate.  When done during byte-compilation, it's a non-issue, but in
the above example it will be done every time you click.

For this reason, pcase uses a memoization mechanism, to try and reuse
previous expansions.  Sadly, this is unreliable because it is difficult
to figure out when two chunks of code are actually identical and to do
so without incurring undue overheads.

The message is just a warning, so you can ignore it.  But the better
option is to try and fix the underlying problem and make sure pcase is
not expanded repeatedly.

E.g. using lexical-binding:

                   keymap ,(make-mode-line-mouse-map
                            'mouse-2
                            (lambda (_event)
                              (interactive "e")
                              (pcase flag
                                (`"-" (dired-sort-menu-set-switches ""))
                                ((or `"t" `"S")
                                 (dired-sort-menu-set-switches ,flag))
                                (`"r"
                                 (dired-sort-menu-toggle-reverse)))))))

or using CL's lexical-let:

                   keymap ,(make-mode-line-mouse-map
                            'mouse-2
                            (lexical-let ((flag flag))
                              (lambda (_event)
                                (interactive "e")
                                (pcase flag
                                  (`"-" (dired-sort-menu-set-switches ""))
                                  ((or `"t" `"S")
                                   (dired-sort-menu-set-switches ,flag))
                                  (`"r"
                                   (dired-sort-menu-toggle-reverse))))))))

-- Stefan


PS: Why do you use (interactive "e") if you then don't use the
`event' argument.



  parent reply	other threads:[~2013-03-04 19:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-01 15:17 pcase-memoize: equal first branch, yet different Michael Heerdegen
2013-03-01 21:45 ` Michael Heerdegen
2013-03-04 19:33 ` Stefan Monnier [this message]
2013-03-05  9:59   ` Ted Zlatanov
2013-03-05 15:41     ` Stefan Monnier
2013-03-05 19:03       ` Ted Zlatanov
2013-03-05 14:13   ` Michael Heerdegen

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=jwvlia3as3p.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /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.