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: Declaring Lisp function types Date: Sat, 24 Feb 2024 02:56:14 -0600 Message-ID: <3cc20ab3-fee7-4b96-9296-604239d761ad@alphapapa.net> References: <86v86ez6af.fsf@gnu.org> 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="24214"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird Cc: acorallo@gnu.org, adam@alphapapa.net, emacs-devel@gnu.org To: eliz@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Feb 24 09:56:53 2024 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 1rdnq1-00064i-4q for ged-emacs-devel@m.gmane-mx.org; Sat, 24 Feb 2024 09:56:53 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdnpY-0005Wv-4W; Sat, 24 Feb 2024 03:56:24 -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 1rdnpW-0005VO-SW for emacs-devel@gnu.org; Sat, 24 Feb 2024 03:56:22 -0500 Original-Received: from bumble.birch.relay.mailchannels.net ([23.83.209.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdnpU-0003yC-0X; Sat, 24 Feb 2024 03:56:22 -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 5BC7E1008DB; Sat, 24 Feb 2024 08:56:17 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a292.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 042F7102080; Sat, 24 Feb 2024 08:56:17 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1708764977; a=rsa-sha256; cv=none; b=B/omy9P/guKcgjhfIDBZX62ZhdHXhQWUxnpYezHqXSGpyC5KfvKx6MSp42oxzqlChyWfqZ 35wcoio9fbn7IqEUrgSJgQgGE/BDAc8r+zJ5vX6ZzolmRNKpy68++Uhj89ihYHxhltbZ4O rdcUWSlV9zr3LLWwdMEYXFGZ+4ZLPy8m3MC/21ei5wi5mUNV4Lfis7g0UCWUZRo5acvkJq gqVy7kdB6e7sU7fAL6tJsofqeJQYTthshOrBrxCSO3p1CKyNmcm5GfIDybE97iwWWiSBBQ UiwXfvd83ulX15US7Texw+m/xyx9nJr5Q2aAuNHKj5fWiXq2NFXURKOjOA5fAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1708764977; 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=BfIRopL7wxF+7FCJW/md6Q4hu4DU0+xB2/g7eNCW5Kw=; b=oJ2hNeykgXVTZNxS8cF6XqPLgnPzCHo5iQD3ip1oN+iL9beB/+brIyxhDPWPmK/a/IvxEC H8z3LAlcq//sbgZsF+yNt69w3HfLF8fp1yyrSvUOhWMJXhUC0WJuRASBl3MhnviP3VyDuV D1hnIE5tN/0yFCkrd20+VLVEFvolCjU5dX0UN6rEj2sY58rw8QxRYhpTbEi/DhYe4F5Y0F BwZPz5z9DfJC9UahJJ4t4Ttn6TeP/ZkLgbjpB0+svJ0+k7cgoxQupmoYEixWSIEpuFliZb /2WWeqPhohv5gIrTmOCU62c1oOl+X2F89L6qP0kwiSgVyy2xUKnm5YBP+V1NAw== ARC-Authentication-Results: i=1; rspamd-55b4bfd7cb-brchs; 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-Minister-Fumbling: 529ef041005015b8_1708764977265_3651481210 X-MC-Loop-Signature: 1708764977265:3234334064 X-MC-Ingress-Time: 1708764977265 Original-Received: from pdx1-sub0-mail-a292.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.112.142.233 (trex/6.9.2); Sat, 24 Feb 2024 08:56:17 +0000 Original-Received: from [10.157.2.182] (unknown [45.130.83.59]) (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-a292.dreamhost.com (Postfix) with ESMTPSA id 4Thghw13DbzNV; Sat, 24 Feb 2024 00:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alphapapa.net; s=dreamhost; t=1708764976; bh=BfIRopL7wxF+7FCJW/md6Q4hu4DU0+xB2/g7eNCW5Kw=; h=Date:To:Cc:Subject:From:Content-Type:Content-Transfer-Encoding; b=GyH/QeXiTiSCdDmGl7plHTnGNMrv+zSkzL3f6+uCRu5k+VGDjeg64TTJWQV7TTrBK gkkxVZrQx4mBIi2Vy/izDmjMQAHKGRiDO14BcE3hvLVdJqRAP/v3/zKQwhHRozoFc4 7gU4k5TBs40CX1ekEUP3Uyc//SqRnvNYyV0UL4YO1bOcIKDpYVi7KwGPPO4rpw6g9N e0aV2ISLpvwqlxtHEetK8MeCT1wjY/CgNwK/hvqNXtGJhGJ0tMC4bxLZGdPROoPbkY IKiXrimjoYQ+dN2t+eZ7a30tBP/I8CtLSf0m9j2RPWcsEwqzE1If+aWUEkTQHfugzz JuX3UFQPe/eyg== Content-Language: en-US In-Reply-To: <86v86ez6af.fsf@gnu.org> Received-SPF: neutral client-ip=23.83.209.25; envelope-from=adam@alphapapa.net; helo=bumble.birch.relay.mailchannels.net X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:316483 Archived-At: >> That looks nice to me. My only suggestion would be to change the symbol >> `function` to `type`, i.e. >> >> (defun sum (a b) >> (declare (type (integer integer) integer)) >> (+ a b)) >> >> Because it would be more concise and descriptive. > > FWIW, Andrea's proposal looks more descriptive to me. "Type" is too > general, whereas "function" is more specific. I don't understand what you mean. ISTM that "type" is exactly what's being declared; "function" would seem redundant, because it's already within a defun form, and less accurate, because it's not declaring the function itself but its types. Another consideration is that using `(declare (function ...))` would preclude allowing `declare-function` forms to be moved into the `declare` form. In fact, in Ement.el, I've already implemented this, please see: https://github.com/alphapapa/ement.el/blob/2b9725accdaed1913b83b2495d3f901ee3aba892/ement-lib.el#L67-L89 Which is used like: https://github.com/alphapapa/ement.el/blob/2b9725accdaed1913b83b2495d3f901ee3aba892/ement-notifications.el#L55 The advantage of allowing `declare-function` to be done as `(declare (function ...))` within a defun form is that it keeps the declaration with the function that makes it necessary, so if the defun is moved to another location, the declaration goes with it; and that then makes it easier to remove the declaration later if it becomes unnecessary. (And, IMHO it looks cleaner than having declare-function forms littering a file.) As you can see, I have a TODO item to propose this upstream, but I hadn't gotten around to it yet. After having had it in "production" for some time without any reported problems, and seeing this thread, now seems like an appropriate time to propose it. :)