From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Declaring Lisp function types Date: Thu, 02 May 2024 13:22:15 +0300 Message-ID: <86plu4ldig.fsf@gnu.org> References: <8634sdjgoj.fsf@gnu.org> <86mspaq4ro.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35604"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org, stefankangas@gmail.com, adam@alphapapa.net, monnier@iro.umontreal.ca, arthur.miller@live.com To: Andrea Corallo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 02 12:23:10 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 1s2Tam-0008yB-Jl for ged-emacs-devel@m.gmane-mx.org; Thu, 02 May 2024 12:23:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s2Ta6-0002qg-Vi; Thu, 02 May 2024 06:22:27 -0400 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 1s2Ta5-0002qG-Jt for emacs-devel@gnu.org; Thu, 02 May 2024 06:22:25 -0400 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 1s2Ta4-0005Ro-4p; Thu, 02 May 2024 06:22:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=4h7otD/0HWxFPHWtQMUDLrh7Vcv0CtMyBsvqF8d39vI=; b=M0ON6NJildkK AtCXed+l0NVo0zUZSAD0SgvUqaUX9/F8BUc4VlKv5Euxo+KUgwowDrfVqEJSi49H2Q70xnmdWbu0f BFFtcDPTeTSN5No01ByGkg1r4BkFDfv6VzAQ9XZb/KRqDKKUtKSR1K7yxVxZYNIuZH98159f59huH jU4zPGAYE5y13foR5C9b4p/gf+a6btfZenM1KRNTnBAtWFHLii/8ov5ec5FLCpLkwrWo3UUlZKaM5 dRC1ay2SAXXCokLlBsMaV53F6yWpcdZnD9n62lGSv3SUBfOLGyqXb+N4A0EL+dvvfn/0E8hjcXsjH Hdd0phfmwElN35rHZz+zvg==; In-Reply-To: (message from Andrea Corallo on Wed, 01 May 2024 16:54:04 -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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:318559 Archived-At: > From: Andrea Corallo > Cc: emacs-devel@gnu.org, stefankangas@gmail.com, adam@alphapapa.net, > monnier@iro.umontreal.ca, arthur.miller@live.com > Date: Wed, 01 May 2024 16:54:04 -0400 > > Eli Zaretskii writes: > > > Without any discussion of what can be @var{type} and no examples, this > > is too abstract. I learned more about it from the other parts of the > > changeset, where you actually use this. So please say something about > > what can be @var{type}, and add one or two examples. > > > > Also, should we say something in NEWS about this? > > Entry added. > > Please let me know if you like me to merge it or I can improve it > further. Thanks. I still have a few minor comments below, but we can handle these after this lands on master. > +@var{type} is a type specifier in the form @code{(function (ARG-1-TYPE > +... ARG-N-TYPE) RETURN-TYPE)}. Argument types can be interleaved with The @code{..} part should be wrapped in @w{..}, to prevent its breaking between two lines. > +symbols @code{&optional} and @code{&rest} to match the @pxref{Argument > +List} of the function. This is not a good use of @pxref. You want @ref there. Moreover, such HTML-like style of cross-references doesn't work well in Texinfo, because at least the info and the printed output formats add stuff, like "See" to the reference. So my recommendation is to use a wordier ...to match the function's arguments (@pxref{Argument List}). > +@lisp > +(defun positive-p (x) > + (declare (type (function (number) boolean))) > + (when (> x 0) > + t)) > +@end lisp If you don't want to have the example broken between two pages, use @group: @lisp @group (defun positive-p (x) (declare (type (function (number) boolean))) (when (> x 0) t)) @end group @end lisp > +@lisp > +(defun cons-or-number (x &optional err-msg) > + (declare (type (function ((or cons number) &optional string) > + (member is-cons is-number)))) > + (if (consp x) > + 'is-cons > + (if (numberp x) > + 'is-number > + (error (or err-msg "Unexpected input"))))) > +@end lisp Same here. > +More types are described in @pxref{Lisp Data Types}. The problematic cross-reference again. > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -1935,6 +1935,10 @@ unibyte string. > > * Lisp Changes in Emacs 30.1 > > +** Function type declaration This should end in a period. Also, since you have updated the manual, it should be marked with "+++". > +It is now possible, using the 'declare' macro, to declare expected types > +of function arguments and return type. Suggest to reword: It is now possible to declare the expected type of a function's arguments using the 'declare' macro.