emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Declaring Lisp function types


From: Andrea Corallo
Subject: Declaring Lisp function types
Date: Fri, 23 Feb 2024 11:02:52 -0500

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]