[LispM] How Good is the Genera Compiler for ANSI Common Lisp?
Raymond Wiker
rwiker at gmail.com
Sat Oct 21 00:55:07 PDT 2017
> On 21 Oct 2017, at 09:38 , Steven Nunez <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/6cf8e878/attachment.html>
More information about the LispM
mailing list