From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrew Hyatt Newsgroups: gmane.emacs.devel Subject: Re: pcase defuns Date: Tue, 29 Mar 2022 21:28:00 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3989"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 30 03:29:16 2022 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 1nZN99-0000nk-IG for ged-emacs-devel@m.gmane-mx.org; Wed, 30 Mar 2022 03:29:15 +0200 Original-Received: from localhost ([::1]:45692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZN98-0004gd-2w for ged-emacs-devel@m.gmane-mx.org; Tue, 29 Mar 2022 21:29:14 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZN81-00040e-3i for emacs-devel@gnu.org; Tue, 29 Mar 2022 21:28:05 -0400 Original-Received: from [2607:f8b0:4864:20::f2d] (port=38875 helo=mail-qv1-xf2d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nZN7z-0008JG-AQ; Tue, 29 Mar 2022 21:28:04 -0400 Original-Received: by mail-qv1-xf2d.google.com with SMTP id jo24so15829909qvb.5; Tue, 29 Mar 2022 18:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=QPpB7T2Z5Md5ZCP/rF/76i1ptCrYSIkeUH/k/YYdwcE=; b=njea8WMM/LzfOs94xtuxi9/YGi7VtaY2nQs5LWthG6Xra5nO1xhnSQ0Bl7zLynB6ub ROySQzXQ9jMTJBROY1809xrdg4eSpzQN+7y5QE0RIu23soYCpzX4v5L2kjS8FhZ4+DAM CI1aDFhgsfKIPUtjV39Nc3z3laXpEK4kXVGcTIGWzFgaIzLY99V3CY8vVg+yNpZYtqnJ mUKgGHsF3z6+1diYZii0G1GU7BF0p8wBQg7bOthrSRQdRt8ZNGeO/d6LlTaLmE7uPp+e Z2/Wn/4nC8BnPeyu823teqcwJBTW3WagqpAPHmGV3gUuDGdyiEZKzUTHdfeyFXfbgWl6 VNxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=QPpB7T2Z5Md5ZCP/rF/76i1ptCrYSIkeUH/k/YYdwcE=; b=vcjaEANRptbhPnnIQW4XJv9aO5Wwkm/avHxsBk1ORKgF4AQXsri5ZhxpPHd0io5Usb aniRVtP39kPdUpELqf91spLMY0k3vVVVM8Dw5QnTnIwRzmOMmO1Bd7U0o8yjWS19sFsG rQ0L7mzUUbl3cBT0UwESgG2XH8I3lTNcsLHLVmdDpOMnCpjhoHDstGb4w8rmAJ2zTmjS Yrv+WIIe04UctPapWDo1A11BlHQ8KNAjNQUBDMCI8ZxO7o9ZyOz7EkIBCwedkf4f48c8 tKEsRaUgI2A7QaCyxYY0sVHXzHlJ5b/wbBeK9yHjGZF9ItAi+9lVYO9lScnIkGpUfDvz OKrw== X-Gm-Message-State: AOAM530eUFzagxW9uTzqrAK2p/aAgjpTk9HQnNuicOXPg0CBTUqvrKYA Fxy/HuScZt08xyxBh2lx5Ktix3dVi+U= X-Google-Smtp-Source: ABdhPJxJ6rCjLbf+RBC+zMnMvmT5nNisDQNH39II+0OQKW9aETjEjh7LWcgaWjlWZ+bipHeipliMNA== X-Received: by 2002:a05:6214:23c5:b0:435:3700:d65 with SMTP id hr5-20020a05621423c500b0043537000d65mr28524785qvb.65.1648603681326; Tue, 29 Mar 2022 18:28:01 -0700 (PDT) Original-Received: from andrews-mbp.lan (pool-173-56-75-166.nycmny.fios.verizon.net. [173.56.75.166]) by smtp.gmail.com with ESMTPSA id v9-20020a05620a0a8900b0067db9cc46a9sm9891271qkg.62.2022.03.29.18.28.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Mar 2022 18:28:00 -0700 (PDT) In-Reply-To: X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::f2d (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2d; envelope-from=ahyatt@gmail.com; helo=mail-qv1-xf2d.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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" Xref: news.gmane.io gmane.emacs.devel:287576 Archived-At: On Mon, Mar 28, 2022 at 12:15 AM Richard Stallman wrote: > [[[ To any NSA and FBI agents reading my email: please consider > ]]] [[[ whether defending the US Constitution against all > enemies, ]]] [[[ foreign or domestic, requires you to follow > Snowden's example. ]]] > > > To give a flavor of what it looks like in practice, here's a > > few pattern defuns from the test: > > > (defun-pattern fibonacci > > "Compute the fibonacci sequence." > > ((0) 0) ((1) 1) ((n) > > (+ (fibonacci (- n 1)) > > (fibonacci (- n 2))))) > > For defining how to compute the value, it is clear and simple. > (Do the patterns handle decomposing lists and other compound > objects?) Yes, it does this. > But defining how to compute the value is not the only job a > defun needs to do. It also needs to record argument names. The way I look at it, it does do this, but it's just structured differently. The normal defun as one arglist. Mine has one per matching clause, which means that it can take a variety of different arguments, all matching. And the arglist and the matching clauses are the same thing, so the arglist can be (n), or ('foo n), or (1 2 (3 n)), etc. Yes, it's weird, but I think the differentiation here is useful, see my next point. > Also, it doesn't seem to offer a way to make the function accept > other arguments beyond the one that the pattern will be applied > to. > > So I think it should take an argument list, and bind all the > argument variables, like this: > > (defun-pattern fibonacci (n) > "Compute the Nth fibonacci number." > ((0) 0) ((1) 1) (t > (+ (fibonacci (- n 1)) > (fibonacci (- n 2))))) > > (defun-pattern sum (x y) > "Compute the sum of natural numbers X and Y." > ((0) y) (t > (1+ (add (1- x) y)))) Thank you for the feedback and your examples. There's a tension here: if I make this fit more with existing patterns, it becomes something that seems closer to just a defun with a pcase in it. Maybe a bit cleaner. In particular, with your proposal, we lose the ability to have fairly different arg patterns, with different numbers of args, or different destructuring patterns. However, I admit that my proposal, without a single arglist, is odd, and may be seen as too esoteric by most. I'm curious to hear more opinions. > > -- > Dr Richard Stallman (https://stallman.org) > Chief GNUisance of the GNU Project (https://gnu.org) > Founder, Free Software Foundation (https://fsf.org) > Internet Hall-of-Famer (https://internethalloffame.org)