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.
This commit is contained in:
2025-02-09 13:29:22 +00:00
parent bd47029bd8
commit bbde84c7d7
2 changed files with 14 additions and 1 deletions

View File

@@ -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)))

View File

@@ -21,7 +21,8 @@
(:use :cl)
(:export
:_ :--> :->>
:while))
:while
:-> :fn))
(defpackage main
(:use :cl :lib.macros)