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:
@@ -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)))
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
(:use :cl)
|
||||
(:export
|
||||
:_ :--> :->>
|
||||
:while))
|
||||
:while
|
||||
:-> :fn))
|
||||
|
||||
(defpackage main
|
||||
(:use :cl :lib.macros)
|
||||
|
||||
Reference in New Issue
Block a user