From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.devel Subject: Declaring Lisp function types Date: Fri, 23 Feb 2024 11:02:52 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1615"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Feb 23 17:15:58 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 1rdYDN-0000Cd-LY for ged-emacs-devel@m.gmane-mx.org; Fri, 23 Feb 2024 17:15:57 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rdYC2-0005jA-KW; Fri, 23 Feb 2024 11:14:34 -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 1rdY0i-00054W-Ou for emacs-devel@gnu.org; Fri, 23 Feb 2024 11:02:52 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rdY0i-0001Eg-EE for emacs-devel@gnu.org; Fri, 23 Feb 2024 11:02:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=XrbqxuaZN0onPEI5MxSfM+m02B0zI1k1q+c3B0N3Vmk=; b=IhUczpPgaa9wTx sWKf2MpeTbVmI5TCPF6OIcL+BJe/mdgHCf1Sx1HPRrynse9WsE05q+rsyT3OScqVyTEhqKhWcdGhc Ein064KMjKzYZzNadcH0FDNA30wZtfkaH6IYT+0jWxnXg9PILOYm4ddeHk3336sxFFqHlfk8HqamR BD78k3bIEuj+T2fKpbEzbt4/T3Q8PiiSTtmsiFJc49oeuiwW49yEFz0DGpWMgONYwUikRXWiJeLpA PNCoVudu98mi+ZrNSo9KCvWxf42WFWVSjx+MExuNFOklGH7y70cJTXPTo6xvJ+WAwVTE+LxudH3f7 yvFo5oeiU6k9lws1uE3A==; Original-Received: from acorallo by fencepost.gnu.org with local (Exim 4.90_1) (envelope-from ) id 1rdY0i-0000O1-30 for emacs-devel@gnu.org; Fri, 23 Feb 2024 11:02:52 -0500 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:316470 Archived-At: Hi all, I'm looking into moving out the function type declarations in 'comp-known-type-specifiers' in order to move them to where the function are actually defined. This to easy maintenance (ATM they get out of sync) and to allow the user for (indeed optionally) declaring function types. In principle I believe we are interested in expressing the the argument types and (maybe optionally) the return type. Some ways CL does this: ;;1 (declaim (ftype (function (integer integer) integer) sum)) ;; ^^inputs ^^output [optional] (defun sum (a b) (declare (integer a b)) (+ a b)) ;;2 (defun sum (a b) (declare (integer a b)) (+ a b)) ;;3 through 'defstar' (a CL library not in the standard) (defun* sum ((a integer) (b integer)) (+ a b)) ;;4 again through 'defstar' (defun* (sum -> integer) ((a integer) (b integer)) (+ a b)) I find 1 a bit too verbose and I think most of times we want a way to do the declaration inside the function definition. I think 2 would be not trivial to implement with our current declare mechanism (as it conflicts) and does *not* allow for declaring the return type. 3 and 4 are I guess are okay assuming we would fine with extending the defun syntax. I initially thought also about adding an ftype declaration like: (defun sum (a b) (declare (ftype (function (integer integer) integer))) (+ a b)) But looked a bit too verbose to me. Finally on top of 'scratch/func-type-decls' (where I there was already a similar work for primitives) I pushed some commits that allows for the following style: (defun sum (a b) (declare (function (integer integer) integer)) (+ a b)) I moved all function declaration out of 'comp-known-type-specifiers' and everything looks functional now. Before writing a ton of changelogs I thought was good to get some feedback anyway. WDYT? Thanks! Andrea