Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!uknet!festival!edcogsci!jeff
From: jeff@aiai.ed.ac.uk (Jeff Dalton)
Subject: Re: Comparison: Beta - Lisp
Message-ID: <Cw4oGq.1H8@cogsci.ed.ac.uk>
Sender: usenet@cogsci.ed.ac.uk (C News Software)
Nntp-Posting-Host: bute.aiai.ed.ac.uk
Organization: AIAI, University of Edinburgh, Scotland
References: <34qbac$ohk@infosrv.edvz.univie.ac.at> <34t8gn$1g6@nz12.rz.uni-karlsruhe.de> <LGM.94Sep11111230@polaris.ih.att.com>
Date: Wed, 14 Sep 1994 16:29:14 GMT
Lines: 47

In article <LGM.94Sep11111230@polaris.ih.att.com> lgm@polaris.ih.att.com (Lawrence G. Mayka) writes:

>I have attached the again-modified version of the benchmark.

>    (dotimes (i n)
>      (declare (fixnum i))
>      (setf (svref perm1 i) i))

I should perhaps point out again that that is not always enough
to get a fully fixnum loop.  I normally use macros like these:

;;; Fixnum iterations

(defmacro fix-dotimes ((var count &optional (result nil))
                       &body body)
  (let ((count-var (gensym)))
    `(let ((,count-var ,count))
       (declare (fixnum ,count-var))
       (do ((,var 0 (fix+ ,var 1)))
           ((fix>= ,var ,count-var)
            ,result)
         (declare (fixnum ,var))
         ,@body))))

(defmacro do-vector-indices ((var vec &optional (result nil))
                             &body body)
  `(fix-dotimes (,var (length (the vector ,vec))
                      ,@(if result (list result)))
     ,@body))

fix+, fix>=, etc are defined like this:

(defmacro fix+ (i j)
  `(the fixnum (+ (the fixnum ,i) (the fixnum ,j))))

(defmacro fix>= (i j)
  `(>= (the fixnum ,i) (the fixnum ,j)))

The root problem seems to be that some Lisps worry that 1 + i may
not be a fixnum even though i is.  I don't think you can always
win even by saying (dotimes (i (the fixnum n)) ...).

It's very easy to see what will happen in KCL, BTW.  Define
the fns and call disassemble.  The C code is sufficiently readable,
because the stuff that's what you'd do in C looks like it is.

-- jeff
