From: Jonathon McKitrick
Subject: Can't figure out unreachable code error
Date: 
Message-ID: <1136590523.030770.218540@g47g2000cwa.googlegroups.com>
Hi all,

here's a function I've written:

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

It's supposed to output 2 fields of a database as an html table.  As it
is here, it finds unreachable code in the format statement below the
commented out statement.  If I uncomment the let, and comment the
do-query, the error goes away but there is obviously no query done.
What have I screwed up here?

From: Rob Warnock
Subject: Re: Can't figure out unreachable code error
Date: 
Message-ID: <z_ydnZpl-8ImByLenZ2dnUVZ_tOdnZ2d@speakeasy.net>
Jonathon McKitrick <···········@bigfoot.com> wrote:
+---------------
| (defun test-web (&optional qname)
|   (let ((aq "SELECT lastname,firstname FROM members")
|         result stuff)
|     (if qname
|       (setf aq (concatenate 'string aq " WHERE lastname= '" qname "'")))
|     (connect '("localhost" "rlg" "root" "none") :database-type :mysql)
|     (setf result "<table><tr><th>Last</th><th>First</th></tr>")
|     (do-query ((lastname firstname) aq)
| ;   (let (lastname firstname)
|               (setf stuff (format nil "<tr><td>~a</td><td>~a</td></tr>"
|                               lastname firstname))
|               (setf result (concatenate 'string result stuff)))
|     (disconnect)
|     (setf result (concatenate 'string result "</table>"))
|     (format t "Result: ~A~%" result)
|     result))
| 
| It's supposed to output 2 fields of a database as an html table.  As it
| is here, it finds unreachable code in the format statement below the
| commented out statement.  If I uncomment the let, and comment the
| do-query, the error goes away but there is obviously no query done.
| What have I screwed up here?
+---------------

Instead of using ";" to "comment out" the LET, try using "#-(and)".
The semicolon doesn't comment out the entire LET form, it only
comments out the first *line* of the LET form. As a result, you've
messed up your parenthesis-matching.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Jonathon McKitrick
Subject: Re: Can't figure out unreachable code error
Date: 
Message-ID: <1136649423.451214.6800@o13g2000cwo.googlegroups.com>
Rob Warnock wrote:

> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.

Thanks a bunch!  I thought for sure there was some higher power at work
keeping me from getting this code working....
From: Jonathon McKitrick
Subject: Re: Can't figure out unreachable code error
Date: 
Message-ID: <1136651305.525720.225310@f14g2000cwb.googlegroups.com>
Rob Warnock wrote:
> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.

I *thought* that was it until I tried this function as well and got the
same error.  No semicolons here, parens seem to match ok.

(defun test-web (&optional qname)
  (let ((aq "SELECT lastname,firstname FROM members"))
    (if qname
      (setf aq (concatenate 'string aq " WHERE lastname= '" qname
"'")))
    (connect '("localhost" "rlg" "root" "none") :database-type :mysql)
    (let ((table "<table><tr><th>Last</th><th>First</th></tr>"))
      (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)))

; 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
From: Jonathon McKitrick
Subject: Re: Can't figure out unreachable code error
Date: 
Message-ID: <1136651276.425987.123220@g49g2000cwa.googlegroups.com>
Rob Warnock wrote:
> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.

I *thought* that was it until I tried this function as well and got the
same error.  No semicolons here, parens seem to match ok.

(defun test-web (&optional qname)
  (let ((aq "SELECT lastname,firstname FROM members"))
    (if qname
      (setf aq (concatenate 'string aq " WHERE lastname= '" qname
"'")))
    (connect '("localhost" "rlg" "root" "none") :database-type :mysql)
    (let ((table "<table><tr><th>Last</th><th>First</th></tr>"))
      (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)))

; 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
From: Jonathon McKitrick
Subject: Re: Can't figure out unreachable code error
Date: 
Message-ID: <1136662016.086508.321690@g14g2000cwa.googlegroups.com>
Rob Warnock wrote:
> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.

Well, that certainly helped until I saw it again here....

; file: /home/jonathon/cvs/cl-rlg/db/db.lisp
; 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

Here is the function in question, similar to the previous one but with
nothing commented out....

(defun test-web (&optional qname)
  (let ((aq "SELECT lastname,firstname FROM members"))
    (if qname
      (setf aq (concatenate 'string aq " WHERE lastname= '" qname
"'")))
    (connect '("localhost" "rlg" "root" "none") :database-type :mysql)
    (let ((table "<table><tr><th>Last</th><th>First</th></tr>"))
      (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)))

What could be the cause here?  I keep thinking it has something to do
with (do-query) but I can't tell what.
From: Jonathon McKitrick
Subject: Re: Can't figure out unreachable code error
Date: 
Message-ID: <1136649374.003601.326540@g49g2000cwa.googlegroups.com>
Rob Warnock wrote:

> The semicolon doesn't comment out the entire LET form, it only
> comments out the first *line* of the LET form. As a result, you've
> messed up your parenthesis-matching.

Thanks a bunch!  I thought for sure there was some higher power at work
keeping me from getting this code working....