aboutsummaryrefslogtreecommitdiff
path: root/lib.macros.lisp
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2025-02-09 13:29:22 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2025-02-11 00:40:19 +0000
commitbbde84c7d7d525f8fcfa3638ae0bca428efc9e67 (patch)
tree2c68ef0dc8e08933cb4b871895a5d75cb82d95ba /lib.macros.lisp
parentbd47029bd83f81ea7ce5fbcc7f9f711a32ba00ca (diff)
downloadcantedraw-bbde84c7d7d525f8fcfa3638ae0bca428efc9e67.tar.gz
cantedraw-bbde84c7d7d525f8fcfa3638ae0bca428efc9e67.tar.bz2
cantedraw-bbde84c7d7d525f8fcfa3638ae0bca428efc9e67.zip
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.
Diffstat (limited to 'lib.macros.lisp')
-rw-r--r--lib.macros.lisp12
1 files changed, 12 insertions, 0 deletions
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)))