From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#27584: 26.0.50; alist-get: Add optional arg TESTFN Date: Sun, 9 Jul 2017 23:45:53 +0900 (JST) Message-ID: References: <87tw2rva7v.fsf@calancha-pc> <87mv8j6y1z.fsf@petton.fr> <87y3s2m76v.fsf@calancha-pc> <8737a83fq6.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1499611652 6210 195.159.176.226 (9 Jul 2017 14:47:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 9 Jul 2017 14:47:32 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) Cc: Nicolas Petton , 27584@debbugs.gnu.org, Tino Calancha To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 09 16:47:24 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUDUS-0000VM-9y for geb-bug-gnu-emacs@m.gmane.org; Sun, 09 Jul 2017 16:47:16 +0200 Original-Received: from localhost ([::1]:36390 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUDUR-0005Pk-Gw for geb-bug-gnu-emacs@m.gmane.org; Sun, 09 Jul 2017 10:47:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUDUJ-0005Pa-2u for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2017 10:47:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUDUF-0004lm-6n for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2017 10:47:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:56318) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dUDUF-0004lR-27 for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2017 10:47:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dUDUE-0000Qu-HS for bug-gnu-emacs@gnu.org; Sun, 09 Jul 2017 10:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 09 Jul 2017 14:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27584 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27584-submit@debbugs.gnu.org id=B27584.14996115641592 (code B ref 27584); Sun, 09 Jul 2017 14:47:02 +0000 Original-Received: (at 27584) by debbugs.gnu.org; 9 Jul 2017 14:46:04 +0000 Original-Received: from localhost ([127.0.0.1]:58995 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUDTI-0000Pc-4S for submit@debbugs.gnu.org; Sun, 09 Jul 2017 10:46:04 -0400 Original-Received: from mail-pf0-f193.google.com ([209.85.192.193]:35807) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUDTG-0000Ou-SC for 27584@debbugs.gnu.org; Sun, 09 Jul 2017 10:46:03 -0400 Original-Received: by mail-pf0-f193.google.com with SMTP id q85so11119514pfq.2 for <27584@debbugs.gnu.org>; Sun, 09 Jul 2017 07:46:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=+Z77JB5Ld6rr8ra/XE6/0kR+eDrnf8j2VLfE6eEDr7A=; b=gdSxMErV6xtrQe5tNSBxMMmHzGsZ5flyhxnVOSejbD/2e4U1cSTiJcqftJPIKSh8IL md44zKPD1531Mr1HzEwGpLfa6GL+ZP0Ye3xOVBbcz/7rUKmBt6Ww6KaVpx9QX7nW2a7j R+tfLAR5V7UlvghBoCgZYJKI6yxgMDViBzjE0o1xFCAZqCamdXot5vmLA0TbczFMWUz7 D1e67RZ5Mt619Q31VMxbXPC7WSdjZf13ICdKNe1DUbHUZA3jztNTvNLVjMArpyBAN+QL SJN50YLqw/9yX7eJsIdPrx49NAMYBGh3xzY2B3TPMExDEN2AAWAY4sEGJeEXGK4+PMtL 4Elg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=+Z77JB5Ld6rr8ra/XE6/0kR+eDrnf8j2VLfE6eEDr7A=; b=fgcDGI62uwThkdu7zBIi+ywv7MoAC6YCsK44ToNhKm2pKlCQ02Z9aquar8pUbQz/jQ BRFysf0a2jduBwjcoyyhtxUeViIq4ZPgm2vwraLP1bcvtoRPPfgvGEfGd/AnWx4aj/b8 v66GbBNMLR9JuwXyXirb7jpuOoFQIYvlEd2ANFSloDh4n5vDzZd7WcLJhbZzL1kTdFjQ fDvzhp0mdz545UVEeWcszRRX5zkft7hiyOG2bwdPZq18iji8dkYU8Uu4NtcDdKfoYnj4 NZwED90bprdk2DoXkslsTnFH8roo9AJSaTUQrGzoySliDfku4S9cy6BwQmKGNo5r7RDw l/xA== X-Gm-Message-State: AIVw111GsNrV4tlTtLca3luZ9hfutfqLnRQRjqHRYk6sfhQuiEHlqNlj raFchEPI1cF8jg== X-Received: by 10.99.95.147 with SMTP id t141mr10277182pgb.263.1499611556580; Sun, 09 Jul 2017 07:45:56 -0700 (PDT) Original-Received: from calancha-pc (170.224.128.101.dy.bbexcite.jp. [101.128.224.170]) by smtp.gmail.com with ESMTPSA id s87sm19279321pfa.86.2017.07.09.07.45.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jul 2017 07:45:55 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:134359 Archived-At: 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?