From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: Re: cond* Date: Sun, 17 Dec 2023 23:41:22 -0600 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23708"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 18 06:42:15 2023 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 1rF6OL-0005xv-H5 for ged-emacs-devel@m.gmane-mx.org; Mon, 18 Dec 2023 06:42:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rF6Nh-0007MQ-KY; Mon, 18 Dec 2023 00:41:33 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rF6Ng-0007JF-Im for emacs-devel@gnu.org; Mon, 18 Dec 2023 00:41:32 -0500 Original-Received: from iguana.tulip.relay.mailchannels.net ([23.83.218.253]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rF6Nb-0000gD-RK; Mon, 18 Dec 2023 00:41:32 -0500 X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 5941D6C1806; Mon, 18 Dec 2023 05:41:25 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a218.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id DE5D96C1328; Mon, 18 Dec 2023 05:41:24 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1702878084; a=rsa-sha256; cv=none; b=HOK1/hJcN5iRkBiS1dglStELHTQTsii8iAk85AOoJ75JmwmCT2/16dFE7fhFY8bAupLSO1 5l6vcw2AsI2DAltAydWJVdTMNzcL/zUdwTNCAc6lr17Uh6xghIiKcQyuILu5c/PXq4eXJX njeFDOcR094+ka4de+FhuY8VL61He3bQIS/LJb8dFz+Ts1VSAqEtXaqk/l2Z2MzohTC7VK +LBORjHWrkbwpZOs9WcTK1EAgKuinS4Bz201E2x8ZGPxoLbBKUvjn2s8C03ss1pCrDNfJ7 1JTtwO3pcDSN4aQ79rl3FShG4zembv0YrAtMj42+lzKTjJOOs4oBgVdGVOTBLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1702878084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=XrVqzZRc+cn8TyBmnltnnnt61pdYIqscUWRDhmjH46g=; b=CwL3sxUa+j498WKbwa3rKEweooYZIqBAM+GciWi8y/vMON7uYjAqRFlzQfIknYwXlhJqqs KxNHwqXFAcb+qvPSutrx2AKupPiVZMhO+ttF5HJDR3Ax8sdYuCoHD0fuJWtUFTEy3H/1zG SyuTGJ2QEtfUpbLCWPMEJikYFEeyom1zQLHC6JDXgkYE5ndz5hw9b879hWSo3Pfpmyp4MO ouqCj4AZfi/3LkOpTrnZXfp3EqR9cYKeuCx0M8EtZn4w1yqmKYfl5/Z0C5l8l7FsWfSO2U NGJW94OWmsoWGsOP1joa2RlWkUNizW2HalW8lMCxMjreTEONChLsAQVIZ/mr/g== ARC-Authentication-Results: i=1; rspamd-d8b88b4b9-9mkvv; auth=pass smtp.auth=dreamhost smtp.mailfrom=adam@alphapapa.net X-Sender-Id: dreamhost|x-authsender|adam@alphapapa.net X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|adam@alphapapa.net X-MailChannels-Auth-Id: dreamhost X-Average-Abaft: 540ba3902ddf749c_1702878085139_490216331 X-MC-Loop-Signature: 1702878085139:3182102158 X-MC-Ingress-Time: 1702878085139 Original-Received: from pdx1-sub0-mail-a218.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.107.188.194 (trex/6.9.2); Mon, 18 Dec 2023 05:41:25 +0000 Original-Received: from [10.43.2.46] (unknown [193.56.116.15]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: adam@alphapapa.net) by pdx1-sub0-mail-a218.dreamhost.com (Postfix) with ESMTPSA id 4StpbS2JbSz1F; Sun, 17 Dec 2023 21:41:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alphapapa.net; s=dreamhost; t=1702878084; bh=XrVqzZRc+cn8TyBmnltnnnt61pdYIqscUWRDhmjH46g=; h=Date:To:Cc:Subject:From:Content-Type:Content-Transfer-Encoding; b=Dct2SvnKLRGpfKYEfS2JGXiN8ViryNdh2fcNg5r+7GJGSGAjJSnJ0syUhkONmhcwv D46vVnerSG0HG0p5H0Zk8tPa+UEeJUvOzy7EO0QQBQn1XIhWsh2cn8kQMxHNzPHm27 UPv7f4UGiqqOCVrBR2+CbBsTdVqNvTZ1gssJniPaU3HV7Qr8OPWAo2om6mJ4s5Awx7 6ZuxKC2z0oC80Obnys3FEmymsVOV3xkHDu5GoEfWvntJfClEAxujIO2hS1hEeMcmzW w4Q/EfK8mPQZ24Wdh6nf8NMenoYAKVRHro6INHaUYshoIhmUv6vy0G6ZEqwe6rIfzh 6ZtEsmQElQbdQ== Content-Language: en-US In-Reply-To: Received-SPF: neutral client-ip=23.83.218.253; envelope-from=adam@alphapapa.net; helo=iguana.tulip.relay.mailchannels.net X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:313972 Archived-At: > To finish the design of cond*, we need to find what features > needed to be added so that it is rare to encounter a pcase > that can't be replaced cleanly. Would people please tell me > about possible examples? Well, one of the most common things I do with pcase is to destructure alists, plists, and structs, often nested at multiple levels. For example: (defun ement-ignore-user (user-id session &optional unignore-p) "Ignore USER-ID on SESSION. If UNIGNORE-P (interactively, with prefix), un-ignore USER." (interactive (list (ement-complete-user-id) (ement-complete-session) current-prefix-arg)) ;; NOTE: Destructures account-data slot of ement-session struct. (pcase-let* (((cl-struct ement-session account-data) session) ;; NOTE: Destructures alist nested in another alist and ;; binds to a variable of a different name than the key. ((map ('content (map ('ignored_users ignored-users)))) (cl-find "m.ignored_user_list" account-data :key (lambda (event) (alist-get 'type event)) :test #'equal))) ...)) (defun ement--room-in-space-p (room space) "Return non-nil if ROOM is in SPACE on SESSION." ;; NOTE: Destructures slots in two structs to alternative variable ;; names, and destructures an alist key in each struct's `local' ;; slot to a variable of the same name. (pcase-let* (((cl-struct ement-room (id parent-id) (local (map children))) space) ((cl-struct ement-room (id child-id) (local (map parents))) room)) ...)) No alternative to pcase that omitted these features could take its place for me. In a large package like Ement.el, where function after function destructures similar objects in similar ways, the benefit of the consistency, conciseness, and flexibility offered by pcase can't be understated. As well, pcase is easily extended with its built-in flexibility, e.g. how easily support was added for the cl-type based pattern. It's a very well-designed system. Then there are pcase-lambda, pcase-dolist, and pcase-setq, all of which use the same underlying facilities and patterns. It's a coherent system: learning pcase opens up this world of useful forms. I would not want to give up these powerful tools which make my programs better and my programming more enjoyable.