It is my general belief that for most cases LISP's speed is comprable
to code written in C for most applications.. Especially as large C
apps end up recreating large portions of lisp(poorly).
However, i have a lisp app which is highly speed-critical--and is
destined to run under CMUCL. Also, really, only 1/3 of the functions
require maximum speed. So, i wrote a few macros:
; just declare a simple way to make a global integer
(defmacro defint( name &optional ( value 0))`(progn (defparameter
,name ,value)(declaim (fixnum ,name))))
; this defines a fast function. It does several things. A fast
function can be declared to be inline, and it can
; have a type. Its parameters can be typed.
(defmacro deffun( name params &rest body )
(unless (consp name) (setf name (list name)))
(let ((type 'atom))
(when (= (length name) 2)
(setf type (pop name)))
`(progn
(defun ,(first name) ,@(let ((names (mapcar (lambda(x)(if
(consp x) (first x) x)) params)))
`(,names ,@(loop for p in params when
(consp p) collect `(declare (,(second p) ,(first p))))))
;(declare (optimize (speed 3)(safety 0)(fixnum-safety 0)))
(the ,type (progn ,@body))))))
(defmacro deffuni( name &rest rst )
`(progn
;(declaim (inline ,(if (consp name) (first (reverse name))
name)))
(deffun ,name ,@rst)))
; a way to do a funcall that doesn't check to see if the target may be
a symbol
(defmacro ffuncall(target &rest args) `(funcall (the function ,target)
,@args))
This helps a lot, and
(deffuni (fixnum from-rank-file) ((rank fixnum) (file fixnum))
(+ file (* rank 8)))
(deffuni square-ok?((square fixnum))(and (>= square 0) (<= square
63)))
run pretty darn fast... Yay!
However, there's still a lot more tha could be done. For example,
lets that include optional types, a function-level macro to rewrite
all mathematics as fixnum even for intermediary results, etc. Yeah, i
could do it, but it occurs to me that it's probably been done before.
Well--has it?
dave
On 18 Sep 2002 13:35:31 -0700, ···········@yahoo.com (David Hanley)
wrote:
>However, there's still a lot more tha could be done. For example,
>lets that include optional types, a function-level macro to rewrite
>all mathematics as fixnum even for intermediary results, etc. Yeah, i
>could do it, but it occurs to me that it's probably been done before.
>Well--has it?
>
>
>dave
If you could write an article or something about this with all the
above code and if it could be put up on the cookbook it would be
simply great.
quasi
--
"look mama - no semicolons !"
quasi <·········@yahoo.com> wrote in message news:<··································@4ax.com>...
>
> If you could write an article or something about this with all the
> above code and if it could be put up on the cookbook it would be
> simply great.
>
> quasi
Ok... I guess i'll do that. What is "the cookbook?" :)
dave