From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] pcase.el: Add type pattern Date: Mon, 09 Mar 2020 14:53:11 -0400 Message-ID: References: <874kuxxuez.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="106488"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Adam Porter Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Mar 09 19:54:00 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 1jBNXK-000RZo-NX for ged-emacs-devel@m.gmane-mx.org; Mon, 09 Mar 2020 19:53:58 +0100 Original-Received: from localhost ([::1]:48148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBNXJ-0005f3-P6 for ged-emacs-devel@m.gmane-mx.org; Mon, 09 Mar 2020 14:53:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44878) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBNWe-00052w-0U for emacs-devel@gnu.org; Mon, 09 Mar 2020 14:53:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBNWc-00066r-Ib for emacs-devel@gnu.org; Mon, 09 Mar 2020 14:53:15 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:59109) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jBNWc-000654-BT for emacs-devel@gnu.org; Mon, 09 Mar 2020 14:53:14 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 9D9B2100F88; Mon, 9 Mar 2020 14:53:13 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 0658F100E11; Mon, 9 Mar 2020 14:53:12 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1583779992; bh=FVc+gQcMeza3eRWw4fhsplvn2vtnMHHXl/e8UrF0nd4=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=MpmHJcxW2x4F3k3vEdRiBeWr4kdPO/Pf1DQlKz16DfUYC+dUlDEzXwW0/e9MkwjX9 nAl4jgfCqahT2a4Q3GQatKkjdaWiQnEesPB0m8FgAZQCeQhrbyPygKCVNrQJY0Zwbm 2pkpMQ2vV9Ey5relxkq2J9Xis2Pw2Byzzk2NHwnfb8Rt1RTtvU8lnzlIjYmTAIzfd3 TfW9Y/8c/vJcinCwp8q0SoP1cCLnAxx5ycTHEwUheSzdaNO5SI2V8MZSQDQ/VCAbyl KWmm6JWsGVsXIo5b84UVo4gULp0ZNk7EAPhnC3TCjqv8QsnXP492gK0jBJHNcwzSFI 7dTfe1hw3cPSw== Original-Received: from alfajor (modemcable157.163-203-24.mc.videotron.ca [24.203.163.157]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id CD8571204AE; Mon, 9 Mar 2020 14:53:11 -0400 (EDT) In-Reply-To: <874kuxxuez.fsf@alphapapa.net> (Adam Porter's message of "Mon, 09 Mar 2020 13:19:48 -0500") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 132.204.25.50 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:245401 Archived-At: > It seemed like an obvious and useful improvement to add a "type" pattern > to pcase, so I prepared this patch. A `type` pattern seems fine, yes. > I wondered if checking for predicates like this was a good way to do so, `cl-typep` does it but I think it's a mistake. We should not rely on such heuristics when we can "do it right", e.g. with a property along the lines of `cl-deftype-satisfies`. > + (pred (or (intern-soft (concat type "p")) > + (intern-soft (concat type "-p")) This fails for those cl-defstructs where the `:predicate` was given another name (or no name at all). We could circumvent the problem by expanding the (type T) check to to a call to `cl-typep`. Stefan PS: Arguably, every type symbol should have a corresponding *class* (currently stored in the `cl--class` symbol for cl-defstruct and eieio objects), so we should then add a bunch of classes for non-structs non-eieio types (such as integer, ...) and we could then define a generic function which takes such a class and returns the predicate to use as a test for this type.