[LispM] How Good is the Genera Compiler for ANSI Common Lisp?

Steven Nunez steven.nunez at illation.com.hk
Sat Oct 21 05:36:39 PDT 2017


Good guess. Sequences are only list and vector. I wonder what other kinds of sequences there are in other implementations?

 

From: Raymond Wiker [mailto:rwiker at gmail.com] 
Sent: 21 October, 2017 15:55
To: steven.nunez at illation.com
Cc: lispm at tunes.org
Subject: Re: [LispM] How Good is the Genera Compiler for ANSI Common Lisp?

 

 





On 21 Oct 2017, at 09:38 , Steven Nunez <steven.nunez at illation.com.hk <mailto:steven.nunez at illation.com.hk> > wrote:

 

Greetings Gents,

 

I’ve started working with some common lisp libraries and noticed a number of compiler warnings, in code that I would not expect it. For example Alexandria shows this:

 

<image001.png>

 

Looking for example at the function ‘shuffle’:

 

(defun shuffle (sequence &key (start 0) end)

  "Returns a random permutation of SEQUENCE bounded by START and END.

Original sequece may be destructively modified, and share storage with

the original one. Signals an error if SEQUENCE is not a proper

sequence."

  (declare (type fixnum start)

           (type (or fixnum null) end))

  (etypecase sequence

    (list

     (let* ((end (or end (proper-list-length sequence)))

            (n (- end start)))

       (do ((tail (nthcdr start sequence) (cdr tail)))

           ((zerop n))

         (rotatef (car tail) (car (nthcdr (random n) tail)))

         (decf n))))

    (vector

     (let ((end (or end (length sequence))))

       (loop for i from start below end

             do (rotatef (aref sequence i)

                         (aref sequence (+ i (random (- end i))))))))

    (sequence

     (let ((end (or end (length sequence))))

       (loop for i from (- end 1) downto start

             do (rotatef (elt sequence i)

                         (elt sequence (+ i (random (- end i)))))))))

  sequence)

 

I do not see any errors here, and having such a basic error in a library like Alexandria would be surprising.

 

Does anyone have any ideas on what might be causing Genera to throw these warnings?

 

 

I'd guess that in Genera, a sequence can only be a list or a vector. Since the typecase form handles list and vector, all possible types of sequences (in Genera) will already have been considered before you get to the form handling the parent type. You may be able to verify this by executing

 

(class-direct-subclasses (find-class 'sequence))

 

[I just checked, and Lispworks 7, Clozure CL and SBCL all show that sequence means either list or vector.]

 

Neat work by the Genera compiler if this is the case!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </archives/lispm/attachments/20171021/c4d44c48/attachment-0001.html>


More information about the LispM mailing list