From: Spiros Bousbouras
Subject: Are all CL implementations this clever ?
Date: 
Message-ID: <5736afc3-1288-4671-bdfb-1c8e9ad650c8@l64g2000hse.googlegroups.com>
In the course of doing some tests I typed the following
on the REPL of SBCL:

(defun foo ()
   (do ( (a 7 (1+ a)) )
  ( (= a 5) (format t "Goodbye~%") 19)
   (format t "a is ~a~%" a)))

and I got

; in: LAMBDA NIL
;     (FORMAT T "Goodbye~%")
; ==>
;   "Goodbye~%"
;
; note: deleting unreachable code
;
; compilation unit finished
;   printed 1 note

I was puzzled by the claim that (format...) is
unreachable but I typed (foo) to see what would
happen and only then did I realise my oversight.

I'm impressed.

From: Lars Rune Nøstdal
Subject: Re: Are all CL implementations this clever ?
Date: 
Message-ID: <48122ea4$0$28887$c83e3ef6@nn1-read.tele2.net>
Spiros Bousbouras wrote:
> In the course of doing some tests I typed the following
> on the REPL of SBCL:
> 
> (defun foo ()
>    (do ( (a 7 (1+ a)) )
>   ( (= a 5) (format t "Goodbye~%") 19)
>    (format t "a is ~a~%" a)))
> 
> and I got
> 
> ; in: LAMBDA NIL
> ;     (FORMAT T "Goodbye~%")
> ; ==>
> ;   "Goodbye~%"
> ;
> ; note: deleting unreachable code
> ;
> ; compilation unit finished
> ;   printed 1 note
> 
> I was puzzled by the claim that (format...) is
> unreachable but I typed (foo) to see what would
> happen and only then did I realise my oversight.
> 
> I'm impressed.


I don't know, but you can control the "cleverness" by the way:

CL-USER> (defun foo ()
            (declare (optimize (speed 0) (safety 3)))
            (do ((a 7 (1+ a)))
                ((= a 5) (format t "Goodbye~%") 19)
              (format t "a is ~a~%" a)))
STYLE-WARNING: redefining FOO in DEFUN
FOO
CL-USER> (defun foo ()
            (declare (optimize (speed 3) (safety 0)))
            (do ((a 7 (1+ a)))
                ((= a 5) (format t "Goodbye~%") 19)
              (format t "a is ~a~%" a)))
; in: LAMBDA NIL
;     (FORMAT T "Goodbye~%")
;
; note: deleting unreachable code
;
; note: deleting unreachable code

;     (1+ A)
; ==>
;   (+ A 1)
;
; note: forced to do GENERIC-+ (cost 10)
;       unable to do inline fixnum arithmetic (cost 1) because:
;       The first argument is a (INTEGER 7), not a FIXNUM.
;       The result is a (VALUES (INTEGER 8) &OPTIONAL), not a (VALUES FIXNUM
;                                                                     &REST T).
;       unable to do inline fixnum arithmetic (cost 2) because:
;       The first argument is a (INTEGER 7), not a FIXNUM.
;       The result is a (VALUES (INTEGER 8) &OPTIONAL), not a (VALUES FIXNUM
;                                                                     &REST T).
;       etc.
;
; compilation unit finished
;   printed 3 notes
STYLE-WARNING: redefining FOO in DEFUN
FOO
CL-USER>

-- 
Lars Rune N�stdal
http://nostdal.org/
From: John Thingstad
Subject: Re: Are all CL implementations this clever ?
Date: 
Message-ID: <op.t96lugqput4oq5@pandora.alfanett.no>
P� Fri, 25 Apr 2008 18:39:07 +0200, skrev Spiros Bousbouras  
<······@gmail.com>:

> In the course of doing some tests I typed the following
> on the REPL of SBCL:
>
> (defun foo ()
>    (do ( (a 7 (1+ a)) )
>   ( (= a 5) (format t "Goodbye~%") 19)
>    (format t "a is ~a~%" a)))
>
> and I got
>
> ; in: LAMBDA NIL
> ;     (FORMAT T "Goodbye~%")
> ; ==>
> ;   "Goodbye~%"
> ;
> ; note: deleting unreachable code
> ;
> ; compilation unit finished
> ;   printed 1 note
>
> I was puzzled by the claim that (format...) is
> unreachable but I typed (foo) to see what would
> happen and only then did I realise my oversight.
>
> I'm impressed.

Naw, this is mostly a SBCL thing. CMUCL from which SBCL was derived was  
written for scientific computing. So more than other compilers it focuses  
on algebraic/numeric optimisations.

Still the fastest code can be gotten from GCL because it compiles to C and  
thus get's the benefit of the C optimizer. But because of ANSI  
compatibility issues I would still not use it. For compiling Maxima though  
it would be a good choice.

--------------
John Thingstad