From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] pcase.el: Add cl-type and type patterns Date: Fri, 16 Jul 2021 18:41:47 -0400 Message-ID: References: <874kuxxuez.fsf@alphapapa.net> <87r1y1wcj4.fsf@alphapapa.net> <87h7yxw5x1.fsf@alphapapa.net> <87a74puq1q.fsf@web.de> <87d09lw3id.fsf@alphapapa.net> <87zhcoqmmz.fsf@web.de> <87wo7s8b73.fsf@alphapapa.net> <87eec53a8r.fsf_-_@alphapapa.net> <87a6mt38fa.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10613"; 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 Sat Jul 17 00:42:41 2021 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 1m4WXZ-0002Yw-6T for ged-emacs-devel@m.gmane-mx.org; Sat, 17 Jul 2021 00:42:41 +0200 Original-Received: from localhost ([::1]:46246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m4WXX-0003GR-G1 for ged-emacs-devel@m.gmane-mx.org; Fri, 16 Jul 2021 18:42:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4WWo-0002bF-OT for emacs-devel@gnu.org; Fri, 16 Jul 2021 18:41:54 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:4524) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4WWl-0006V1-Lp for emacs-devel@gnu.org; Fri, 16 Jul 2021 18:41:53 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 57E0780937; Fri, 16 Jul 2021 18:41:49 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 27C1A80668; Fri, 16 Jul 2021 18:41:48 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1626475308; bh=el+arvTDPk8xfSW+Jbf7q0bh+aV05Gg5lF3xidgGlEU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=K2kRAZ7/7S38rU95XUFtKt2IyaSZzO9qSr6csZEyFePYsFdhXPhj7r5xzc/piOthL +IGwas9Dbf3ITeTuMLeeePNFdocW0fJn7w9wLoFbV6mo8d2p4ptphxutDRp3T1Y4N5 e56IC087Bu25RNpB4NiIbbV7WS+gYQjXX/Eg67EnanTDqnSP9SC4QxWR1o/908vPjA ScpeXjMcuD+H6fHfvukRxIqUCAnFGA/EanxJciizrP4daNSBV13pPB6ylz8VIPQl9V LRnS5+aSLe+bTMvq+Pd4x568q/Uk7/6QMgIZ0g+lRbzR/0IML6T67igtfdzbrUbwxR YUam+vzr9LFXg== Original-Received: from alfajor (unknown [216.154.29.138]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id DF53E120533; Fri, 16 Jul 2021 18:41:47 -0400 (EDT) In-Reply-To: <87a6mt38fa.fsf@alphapapa.net> (Adam Porter's message of "Sat, 10 Jul 2021 21:12:41 -0500") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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:271318 Archived-At: > +@item (cl-type @var{type}) > +Matches if @var{expval} is of type @var{type}, which is a symbol or > +list as accepted by @ref{cl-typep,,,cl,Common Lisp Extensions}. Rather than mention "symbol or list", I'd only refer to `cl-typep`, maybe something like: Matches if @var{expval} is of type @var{type}, which is type descriptor as accepted by @ref{cl-typep,,,cl,Common Lisp Extensions}. The rest of the first patch looks good to me. > +(pcase-defmacro type (type) > + "Pcase pattern that matches objects of TYPE. > +This checks using a predicate named `TYPEp' or `TYPE-p', as > +appropriate. For matching structs defined with `cl-defstruct', > +the `cl-type' pattern matcher should be used instead." > + (let* ((type (symbol-name type)) > + (pred (or (intern-soft (concat type "p")) > + (intern-soft (concat type "-p")) > + (error "Unknown type: %s" type)))) > + `(pred ,pred))) I'm not convinced this second patch is worth the trouble: (type FOO) is not significantly shorter or simpler than (pred FOO-p) but it is inherently brittle because `intern-soft` may return non-nil even though there's no predicate by that name, and it may also let you use a "type" which really isn't one such as `cl--struct-name` or `looking-at`. `cl-type` provides that functionality in a cleaner and more reliable way (it still also relies to some extent on similar heuristic as your code, admittedly, but I've been working to get rid of it). Stefan