From bbde84c7d7d525f8fcfa3638ae0bca428efc9e67 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 9 Feb 2025 13:29:22 +0000 Subject: Add type alias for function and macro for defining functions with type specifier `fn' is a convenience macro for defining functions with a type specifier. Only really matters for `sbcl` and other hard-optimising Lisp interpreters which actually take these seriously. --- lib.macros.lisp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib.macros.lisp') diff --git a/lib.macros.lisp b/lib.macros.lisp index f96636d..057a89f 100644 --- a/lib.macros.lisp +++ b/lib.macros.lisp @@ -66,3 +66,15 @@ Like the `|>' operator in Ocaml." `(loop :while ,condition :do (progn ,@body))) + +(deftype -> (args result) + "Type alias for function." + `(function ,args ,result)) + +(defmacro fn (name lambda-list type &body body) + "Construct a function `NAME' with a declared function type `TYPE' that takes +arguments `LAMBDA-LIST' with body `BODY'." + `(progn + (declaim (ftype ,type ,name)) + (defun ,name ,lambda-list + ,@body))) -- cgit v1.2.3-13-gbd6f