Since comp.lang.lisp seems to be slowly turning into a shoe bazaar, I thought I would announce this library here. Hopefully some people will find it useful.
DEFSTAR is a collection of macros that can be used as replacements for the forms DEFUN, DEFMETHOD, DEFGENERIC, DEFVAR, DEFPARAMETER, LABELS, FLET and LAMBDA. The names are the same as the forms they replace, with a star at the end, eg DEFUN*.
Repository: http://bitbucket.org/eeeickythump/defstar/
Main features are:
- Easy in-line type declaration within lambda lists (no more separate DECLARE statements)
- Easy declaration of the return type of a function -- also within the definition of the function
- Assertions that check the type, value, or anything else about arguments prior to entering the function body, and prior to returning from the function
- Replacements for DEFUN, DEFMETHOD, DEFGENERIC, LAMBDA, FLET, LABELS, DEFVAR, DEFPARAMETER
- Supports &key, &optional, &rest and &aux arguments
- Supports specialised lambda lists (defmethod)
- Supports assertions and typechecking for functions that return multiple values.
Code: Select all
;; A function that takes two reals as arguments, and returns a real.
(defun* (sum -> real) ((a real) (b real))
(+ a b))
Code: Select all
(PROGN (DECLAIM (FTYPE (FUNCTION (REAL REAL) REAL) SUM))
(DEFUN SUM (A B)
(DECLARE (TYPE REAL B) (TYPE REAL A))
(THE REAL (+ A B))))
DEFSTAR does the same as TYPEDVAR-COMMON-LISP (in fact the assertions facility means it does more), but works solely through use of different forms: DEFUN*, LAMBDA*, etc. No reader macros and no code-walking. No dependencies other than ASDF (optional). It should play well with all other CL libraries. Just
Code: Select all
(use-package :defstar)
DEFSTAR has mainly been tested in Clozure CL, and a bit on SBCL. All macros expand to completely uncontroversial CL so in theory it should be portable across all conformant implementations.
See http://bitbucket.org/eeeickythump/defstar/wiki/ for more details, examples and documentation.