From: Tino Calancha <tino.calancha@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Nicolas Petton <nicolas@petton.fr>,
27584@debbugs.gnu.org, Tino Calancha <tino.calancha@gmail.com>
Subject: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN
Date: Sun, 9 Jul 2017 23:45:53 +0900 (JST) [thread overview]
Message-ID: <alpine.DEB.2.20.1707092333480.19620@calancha-pc> (raw)
In-Reply-To: <jwvh8yont31.fsf-monnier+emacsbugs@gnu.org>
On Fri, 7 Jul 2017, Stefan Monnier wrote:
>> + (declare (compiler-macro
>> + (lambda (_)
>> + `(pcase ,pred
>> + ('eq (assq ,key ,alist))
>> + ((or 'equal 'nil) (assoc ,key ,alist))
>> + ((guard (and (macroexp-const-p ,key) (eq ,pred 'eql)))
>> + (if (floatp ,key)
>> + (assoc ,key ,alist) (assq ,key ,alist)))
>> + (_ (assoc-default ,key ,alist ,pred nil 'full))))))
>
> This replaces a call to the function with a chunk of code which does
> `pcase`, which is not what we want: we want the `pcase` to be executed
> during compilation and if we can't choose which branch to follow, then
> we just keep the call unchanged (which is why, in my define-inline
> example, the pcase was outside of `inline-quote`).
Thank you Stefan. After playing a bit with this i'd like to
ask you something.
I rewrote it as follows:
(declare (compiler-macro
(lambda (form)
(pcase pred
(''eq `(assq ,key ,alist))
((or ''equal 'nil) `(assoc ,key ,alist))
((and (guard (macroexp-const-p key)) ''eql)
(if (floatp key)
`(assoc ,key ,alist) `(assq ,key ,alist)))
(t form)))))
Apparently, it works as a charm:
*) For example, if i compile a file with content:
;; -*- lexical-binding: t; -*-
(defun run ()
(assoc-predicate 999 '((1 . "a") (2 . "b")) 'eql))
*) tmp.elc contains, something like:
(defalias 'run #[0 "\300\301\236\207" [999 ((1 . "a") (2 . "b"))] 2])
**) But note what happens if the file contains:
;; -*- lexical-binding: t; -*-
(defun run ()
(assoc-predicate (let ((x 999)) x) '((1 . "a") (2 . "b")) 'eql))
**) tmp.elc shows:
(defalias 'run #[0 "\300\301\211\262\302\303#\207" [assoc-predicate 999
((1 . "a") (2 . "b")) eql] 4])
That is, in the pcase fails the condition:
(and (guard (macroexp-const-p key)) ''eql)
so that the compiler macro doesn't change the form.
But we know that:
(macroexp-const-p (let ((x 999)) x))
=> t
So, i would expect to **) compiles to similar code as *).
What is wrong with my assumptions?
next prev parent reply other threads:[~2017-07-09 14:45 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-05 3:22 bug#27584: 26.0.50; alist-get: Add optional arg TESTFN Tino Calancha
2017-07-05 8:53 ` Tino Calancha
2017-07-05 9:19 ` Nicolas Petton
2017-07-05 13:18 ` Tino Calancha
2017-07-06 6:05 ` Tino Calancha
2017-07-06 6:13 ` Stefan Monnier
2017-07-06 6:20 ` Tino Calancha
2017-07-06 9:36 ` Nicolas Petton
2017-07-06 10:55 ` Tino Calancha
2017-07-06 11:06 ` Nicolas Petton
2017-07-06 15:07 ` Stefan Monnier
2017-07-07 6:48 ` Tino Calancha
2017-07-07 7:46 ` Eli Zaretskii
2017-07-07 8:09 ` Nicolas Petton
2017-07-07 15:53 ` Stefan Monnier
2017-07-09 14:45 ` Tino Calancha [this message]
2017-07-10 12:04 ` Michael Heerdegen
2017-07-10 12:28 ` Tino Calancha
2017-07-10 12:38 ` Michael Heerdegen
2017-07-10 12:47 ` Michael Heerdegen
2017-07-10 13:02 ` Tino Calancha
2017-07-10 13:18 ` Michael Heerdegen
2017-07-10 12:50 ` Michael Heerdegen
2017-07-06 14:56 ` Nicolas Petton
2017-07-07 6:39 ` Tino Calancha
2017-07-07 8:11 ` Nicolas Petton
2017-07-07 8:22 ` Tino Calancha
2017-07-07 8:34 ` Nicolas Petton
2017-07-07 15:49 ` Stefan Monnier
2017-07-07 15:54 ` Nicolas Petton
2017-07-07 19:47 ` Nicolas Petton
2017-07-08 6:30 ` Eli Zaretskii
2017-07-08 7:02 ` Tino Calancha
2017-07-08 7:14 ` Eli Zaretskii
2017-07-08 11:32 ` Nicolas Petton
2017-07-08 11:46 ` Eli Zaretskii
2017-07-09 14:48 ` Tino Calancha
2017-07-09 19:18 ` Nicolas Petton
2017-07-11 8:08 ` Nicolas Petton
2017-07-11 9:19 ` Tino Calancha
2017-07-12 17:36 ` Michael Heerdegen
2017-07-14 5:19 ` Tino Calancha
2017-07-14 11:16 ` Nicolas Petton
2017-07-17 13:38 ` Tino Calancha
2017-08-01 16:37 ` Nicolas Petton
2017-08-01 16:49 ` Nicolas Petton
2017-08-01 18:53 ` Eli Zaretskii
2017-07-08 11:29 ` Nicolas Petton
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=alpine.DEB.2.20.1707092333480.19620@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=27584@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=nicolas@petton.fr \
/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.