From: Jonathon McKitrick
Subject: Why the 'deleting unreachable code' message here?
Date: 
Message-ID: <1136620882.527914.179550@g14g2000cwa.googlegroups.com>
This is a pretty straightforward function to turn a simple SQL query
into an html table:

(defun test-web (&optional qname)
  (let ((aq "SELECT lastname,firstname FROM members")
        (table "<table><tr><th>Last</th><th>First</th></tr>")
        (stuff nil)
        )
    (if qname
      (setf aq (concatenate 'string aq " WHERE lastname= '" qname
"'")))
    (connect '("localhost" "rlg" "root" "none") :database-type :mysql)
    (do-query ((lastname firstname) aq)
              (setf table (format nil
"~a<tr><td>~a</td><td>~a</td></tr>"
                                  table lastname firstname)))
    (disconnect)
    (setf table (concatenate 'string table "</table>"))
    table))

As is, it compiles (SBCL) and says 'stuff' is unused.  If you add a
semicolon and comment out the 'stuff' declaration, you get this:

; in: DEFUN TEST-WEB
;     (FORMAT NIL
;           "~a<tr><td>~a</td><td>~a</td></tr>"
;           DB::TABLE
;           DB::LASTNAME
;           DB::FIRSTNAME)
; ==>
;   "~a<tr><td>~a</td><td>~a</td></tr>"
; 
; note: deleting unreachable code

What causes this?
From: Barry Margolin
Subject: Re: Why the 'deleting unreachable code' message here?
Date: 
Message-ID: <barmar-80F039.16522607012006@comcast.dca.giganews.com>
In article <························@g14g2000cwa.googlegroups.com>,
 "Jonathon McKitrick" <···········@bigfoot.com> wrote:

> This is a pretty straightforward function to turn a simple SQL query
> into an html table:
> 
> (defun test-web (&optional qname)
>   (let ((aq "SELECT lastname,firstname FROM members")
>         (table "<table><tr><th>Last</th><th>First</th></tr>")
>         (stuff nil)
>         )
>     (if qname
>       (setf aq (concatenate 'string aq " WHERE lastname= '" qname
> "'")))
>     (connect '("localhost" "rlg" "root" "none") :database-type :mysql)
>     (do-query ((lastname firstname) aq)
>               (setf table (format nil
> "~a<tr><td>~a</td><td>~a</td></tr>"
>                                   table lastname firstname)))
>     (disconnect)
>     (setf table (concatenate 'string table "</table>"))
>     table))
> 
> As is, it compiles (SBCL) and says 'stuff' is unused.  If you add a
> semicolon and comment out the 'stuff' declaration, you get this:

Are you sure you only commented out the STUFF binding, and not also the 
close parenthesis that you show on the line after it above?  The 
conventional way to format a LET is 

(let ((aq ...)
      (table ...)
      (stuff nil))
  <body>)

but if you put a semicolon at the beginning of the stuff line, the body 
will become part of the declarations.

> 
> ; in: DEFUN TEST-WEB
> ;     (FORMAT NIL
> ;           "~a<tr><td>~a</td><td>~a</td></tr>"
> ;           DB::TABLE
> ;           DB::LASTNAME
> ;           DB::FIRSTNAME)
> ; ==>
> ;   "~a<tr><td>~a</td><td>~a</td></tr>"
> ; 
> ; note: deleting unreachable code
> 
> What causes this?

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***