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 ++++++++++++ packages.lisp | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) 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))) diff --git a/packages.lisp b/packages.lisp index 8e66c78..f7e56a6 100644 --- a/packages.lisp +++ b/packages.lisp @@ -21,7 +21,8 @@ (:use :cl) (:export :_ :--> :->> - :while)) + :while + :-> :fn)) (defpackage main (:use :cl :lib.macros) -- cgit v1.2.3-13-gbd6f