[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pcase-memoize: equal first branch, yet different
From: |
Stefan Monnier |
Subject: |
Re: pcase-memoize: equal first branch, yet different |
Date: |
Mon, 04 Mar 2013 14:33:41 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
> 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.