From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Richard Stallman Newsgroups: gmane.emacs.devel Subject: Re: pcase defuns Date: Mon, 28 Mar 2022 00:15:44 -0400 Message-ID: References: Reply-To: rms@gnu.org Content-Type: text/plain; charset=Utf-8 Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16442"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Andrew Hyatt Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Mar 28 06:16:26 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 1nYgnq-00042V-FM for ged-emacs-devel@m.gmane-mx.org; Mon, 28 Mar 2022 06:16:26 +0200 Original-Received: from localhost ([::1]:46312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nYgnp-0000zG-Hc for ged-emacs-devel@m.gmane-mx.org; Mon, 28 Mar 2022 00:16:25 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:55892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nYgnB-0000Dm-HV for emacs-devel@gnu.org; Mon, 28 Mar 2022 00:15:45 -0400 Original-Received: from [2001:470:142:3::e] (port=55754 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nYgnB-0002qo-6A; Mon, 28 Mar 2022 00:15:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=Date:References:Subject:In-Reply-To:To:From: mime-version; bh=jDDUC6Zg3/ONrfJQ/Q99os7bDXqfBXmnaVqk4I/hetM=; b=KIAyiOpfsM9Q FoXkfYcpk4/1Y1XsUPaOxrw+JilIXeYr6ZO2LafVENMTu98LOeq61Y2hFOwJDMzYe8RkTSWRQCDE4 6/4G271pfR7Xi82pHU2magzFqhMCIilo9fJQuI9BaqyaZvF6LwfQtmqE7QGnt57hrhIumpFdfMIKV 1k0GmQtTBgoY6bVHnF+NAwcCi6f6BZG7dx08XpLaPXt4etmVwnFjM1lZROpF3wFDh9ozazgQ93B3n qLtyxOe1ZQBlQ1BLdUbxHwBSNz7S3rqZeb/0bPsgvhyrhQEfGY3F2bdnjQOPo+2C+lfnH2dZETigd 3Fly46F+EaRcUN46n+BdMg==; Original-Received: from rms by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1nYgnA-000696-5m; Mon, 28 Mar 2022 00:15:44 -0400 In-Reply-To: (message from Andrew Hyatt on Sat, 26 Mar 2022 13:41:26 -0400) 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:287519 Archived-At: [[[ 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?) But defining how to compute the value is not the only job a defun needs to do. It also needs to record argument names. 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)))) -- 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)