From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Zhu Zihao Newsgroups: gmane.emacs.devel Subject: Re: Slot accessing issues in EIEIO Date: Fri, 08 May 2020 17:12:16 +0800 Message-ID: <87v9l6g58v.wl-all_but_last@163.com> References: <87a72lhf3b.wl-all_but_last@163.com> <878si5gmt7.wl-all_but_last@163.com> <877dxoh1m6.wl-all_but_last@163.com> <874kssgzrf.wl-all_but_last@163.com> <87k11nzvc2.fsf@bernoul.li> <87wo5nf7bv.wl-all_but_last@163.com> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Fri_May__8_17:12:16_2020-1" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="56027"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL/10.8 EasyPG/1.0.0 Emacs/27.0 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: Jonas Bernoulli , Zhu Zihao , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri May 08 11:13:39 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jWz4c-000EST-Dj for ged-emacs-devel@m.gmane-mx.org; Fri, 08 May 2020 11:13:38 +0200 Original-Received: from localhost ([::1]:41394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWz4b-0002zY-Ek for ged-emacs-devel@m.gmane-mx.org; Fri, 08 May 2020 05:13:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57574) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWz3w-00024h-Jy for emacs-devel@gnu.org; Fri, 08 May 2020 05:12:56 -0400 Original-Received: from m12-17.163.com ([220.181.12.17]:35573) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jWz3s-0004WU-28 for emacs-devel@gnu.org; Fri, 08 May 2020 05:12:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:Message-ID:From:Subject:MIME-Version; bh=P6KjZ KK8g+MVE9jml7i4KfKrLejNIi4S4RjoKkfTov0=; b=kPdTFnZ875EcXTw8CLwR8 8B7jsjb+GFlBURURH0RQryeITSNAKIOSMVUr7ej2SFCxptX1x1hfiTkEOBYt56Pn WQ9aVP4A/g1A0reXuYJOS5sUEOXyx4nXLVtA2YG3oRnAomyiZGcpcEJhguVbepQX r0t5xXadybRDao6C8RV69E= Original-Received: from archlinux.163.com (unknown [14.121.132.235]) by smtp13 (Coremail) with SMTP id EcCowACnejx4IrVevBEFBg--.18S2; Fri, 08 May 2020 17:12:28 +0800 (CST) In-Reply-To: X-Face: :]]%@R1{oDt0%iKgI@Kga#OZ; ogt+%OOne&J4#E*O,TIlI)yEFw--I\:3s~EV97GI$1.1!}8inmF9UgtUBB@#8>'8NWNC8qg/v*OLfQB; Z:@G3HeNf3u& ,&HpBGv%?p{bzsl'|5T";1&X X-CM-TRANSID: EcCowACnejx4IrVevBEFBg--.18S2 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxU1pnQUUUUU X-Originating-IP: [14.121.132.235] X-CM-SenderInfo: pdoosuxxwbztlvw6il2tof0z/xtbBaw0er1et0NltuAABsw Received-SPF: pass client-ip=220.181.12.17; envelope-from=all_but_last@163.com; helo=m12-17.163.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/08 05:12:37 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:249253 Archived-At: --Multipart_Fri_May__8_17:12:16_2020-1 Content-Type: text/plain; charset=US-ASCII On Fri, 08 May 2020 11:48:22 +0800, Stefan Monnier wrote: > > > Maybe we can fix the eieio pattern of pcase. > > > > In this piece of code: > > > > (defclass test-class () ((slot))) > > > > (pcase (make-instance 'test-class) > > ((eieio slot) > > slot)) > > ;; => unbound > > > > An unbound marker will be returned on the fly without running slot-unbound > > in pcase with eieio pattern. Is it reasonable? > > It should likely obey the bound/unbond distinction, and call > slot-missing when applicable, yes. Patch welcome. > > > Stefan I just give it a try ;) --Multipart_Fri_May__8_17:12:16_2020-1 Content-Type: text/plain; type=patch; name="0001-Make-pcase-pattern-eieio-respect-slot-access-related.patch"; charset=US-ASCII Content-Disposition: attachment; filename="0001-Make-pcase-pattern-eieio-respect-slot-access-related.patch" Content-Transfer-Encoding: 7bit >From 2fe8fe4c1ae1becb4439bb64576a43ec3fd0b5b7 Mon Sep 17 00:00:00 2001 From: Zhu Zihao Date: Fri, 8 May 2020 17:01:56 +0800 Subject: [PATCH] Make pcase pattern 'eieio' respect slot access related functions. * lisp/emacs-lisp/eieio.el: Make pcase pattern respect slot-missing and slot-unbound --- lisp/emacs-lisp/eieio.el | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lisp/emacs-lisp/eieio.el b/lisp/emacs-lisp/eieio.el index fe2b80be01e..999d75f79e9 100644 --- a/lisp/emacs-lisp/eieio.el +++ b/lisp/emacs-lisp/eieio.el @@ -359,16 +359,13 @@ eieio ;; FIXME: `pcase' does not do a good job here of sharing tests&code among ;; various branches. `(and (pred eieio-object-p) - (app eieio-pcase-slot-index-table ,is) - ,@(mapcar (lambda (field) - (let* ((name (if (consp field) (car field) field)) - (pat (if (consp field) (cadr field) field)) - (i (make-symbol "index"))) - `(and (let (and ,i (pred natnump)) - (eieio-pcase-slot-index-from-index-table - ,is ',name)) - (app (pcase--flip aref ,i) ,pat)))) - fields)))) + ,@(mapcar (lambda (field) + (pcase-exhaustive field + (`(,name ,pat) + `(app (pcase--flip eieio-oref ',name) ,pat)) + ((pred symbolp) + `(app (pcase--flip eieio-oref ',field) ,field)))) + fields)))) ;;; Simple generators, and query functions. None of these would do ;; well embedded into an object. -- 2.26.2 --Multipart_Fri_May__8_17:12:16_2020-1--