summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md36
1 files changed, 36 insertions, 0 deletions
diff --git a/README.md b/README.md
index bfe785c..418f3da 100644
--- a/README.md
+++ b/README.md
@@ -64,3 +64,39 @@ The above would expand out into
(:DOCUMENTATION "A point in real 3d space"))
See `def:class`'s docstring for details.
+
+## `def:fast`
+
+Common Lisp compilers like SBCL can produce extremely fast code
+... if, that is, you help them out a little.
+
+Declaring types and `optimize` declare expressions can be a little
+verbose and irritating to add to every function that you want to be
+fast.
+
+`def:fast` lightens some of the typing load by embedding types inside
+the lambda list, and by declaring the return type of functions. E.g.:
+
+
+ (defun list-of-fixnum-p (xs)
+ (and (listp xs) (every #'sb-int:fixnump xs)))
+
+ (deftype list-of-fixnum ()
+ '(satisfies list-of-fixnum-p))
+
+ (def:fast sum-fixnum ((x fixnum) (y fixnum) &rest (xs list-of-fixnum)) -> fixnum
+ "Sums fixnums"
+ (+ x y (reduce #'+ xs)))
+
+
+The above expands into
+
+ (DEFUN SUM-FIXNUM (X Y &REST XS)
+ "Sums fixnums"
+ (DECLARE (TYPE LIST-OF-FIXNUM XS)
+ (TYPE FIXNUM Y X)
+ (VALUES FIXNUM)
+ (OPTIMIZE (SPEED 3) (SAFETY 0)))
+ (+ x y (REDUCE #'+ XS)))
+
+