From: Brian Seery
Subject: Please Help.. Newbie with some Q's
Date: 
Message-ID: <84qb9e$vfj$1@fraggle.esatclear.ie>
Hi there I am totally new to lisp and lost, and I have a couple of
questions. I am trying to write an immatation of ELIZA
****************************************************************************
***************
    Here is my CODE
****************************************************************************
***************
(defun doctor()
  (defvar doctor nil)
  (let ((doctor nil))
    (print '(speak up))
    (print '>)
    (do ((input (read) (read)))
        ((endp input)
         (print '(ok -- our time is up anyway))
         (values))
     (multiple-value-bind(result value)
                         (doctor-tree input)
       (if value
           (print value)
           (progn
             (print '(i did not understand that))
             (print '(type nil if you want to stop)))))
     (print '>))))


(define-tree doctor-tree
             (brnchs(i am worried about * words if-end-rtn
                       `(how long have you been worried about ,@words))))
****************************************************************************
***************
    Here are the ERRORS I am getting
****************************************************************************
***************
; (TOP-LEVEL-FORM 1)
;;;*** Warning in DOCTOR: RESULT is bound but not referenced
;;;*** Warning in DOCTOR: DOCTOR is bound but not referenced
; DOCTOR
;;;*** Warning in (TOP-LEVEL-FORM 2): DOCTOR-TREE assumed special
;;;*** Warning in (TOP-LEVEL-FORM 2): AM assumed special
;;;*** Warning in (TOP-LEVEL-FORM 2): WORRIED assumed special
;;;*** Warning in (TOP-LEVEL-FORM 2): ABOUT assumed special
;;;*** Warning in (TOP-LEVEL-FORM 2): WORDS assumed special
;;;*** Warning in (TOP-LEVEL-FORM 2): IF-END-RTN assumed special
;;;*** Warning in (TOP-LEVEL-FORM 2): WORDS assumed special
; (TOP-LEVEL-FORM 2)
; (TOP-LEVEL-FORM 3)
; (TOP-LEVEL-FORM 4)

The following functions are undefined:
I which is referenced by (TOP-LEVEL-FORM 2)
DEFINE-TREE which is referenced by (TOP-LEVEL-FORM 2)
DOCTOR-TREE which is referenced by DOCTOR
BRNCHS which is referenced by (TOP-LEVEL-FORM 2)
****************************************************************************
***************
I am totally lost could somebody please help me out it would be much
appreciated

Thanks in advance.

Brian

From: Barry Margolin
Subject: Re: Please Help.. Newbie with some Q's
Date: 
Message-ID: <zM3c4.26$KR.589@burlma1-snr2>
In article <············@fraggle.esatclear.ie>,
Brian Seery <······@esatclear.ie> wrote:
>Hi there I am totally new to lisp and lost, and I have a couple of
>questions. I am trying to write an immatation of ELIZA
>****************************************************************************
>***************
>    Here is my CODE
>****************************************************************************
>***************
>(defun doctor()
>  (defvar doctor nil)

DEFVAR should be used at top level, not inside a function.  It's used to
declare global variables.

If you want the DOCTOR variable to be shared just between a small number of
functions, you can put (declare (special doctor)) in them.  In the main
function that creates it you should put this declaration just after the
following line:

>  (let ((doctor nil))

In the other functions, which only assign to it (I'm guessing this is the
doctor's "memory" of previous statements the patient has made) you would
put it immediately after the DEFUN line.

>    (print '(speak up))
>    (print '>)
>    (do ((input (read) (read)))
>        ((endp input)
>         (print '(ok -- our time is up anyway))
>         (values))
>     (multiple-value-bind(result value)
>                         (doctor-tree input)
>       (if value
>           (print value)
>           (progn
>             (print '(i did not understand that))
>             (print '(type nil if you want to stop)))))
>     (print '>))))
>
>
>(define-tree doctor-tree
>             (brnchs(i am worried about * words if-end-rtn
>                       `(how long have you been worried about ,@words))))
>****************************************************************************
>***************
>    Here are the ERRORS I am getting
>****************************************************************************
>***************
>; (TOP-LEVEL-FORM 1)
>;;;*** Warning in DOCTOR: RESULT is bound but not referenced

In your MULTIPLE-VALUE-BIND form, you bind RESULT to the first value
returned by DOCTOR-TREE, but then you never use this variable.  To make the
warning go away, you can put:

(declare (ignore result))

before the IF.

>;;;*** Warning in DOCTOR: DOCTOR is bound but not referenced
>; DOCTOR
>;;;*** Warning in (TOP-LEVEL-FORM 2): DOCTOR-TREE assumed special
>;;;*** Warning in (TOP-LEVEL-FORM 2): AM assumed special
>;;;*** Warning in (TOP-LEVEL-FORM 2): WORRIED assumed special
>;;;*** Warning in (TOP-LEVEL-FORM 2): ABOUT assumed special
>;;;*** Warning in (TOP-LEVEL-FORM 2): WORDS assumed special
>;;;*** Warning in (TOP-LEVEL-FORM 2): IF-END-RTN assumed special
>;;;*** Warning in (TOP-LEVEL-FORM 2): WORDS assumed special

It seems like you haven't defined the DEFINE-TREE macro yet.  So the
compiler assumes it's an ordinary function, and all the unquoted symbols in
the form are variable references.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Martti Halminen
Subject: Re: Please Help.. Newbie with some Q's
Date: 
Message-ID: <3870CA5C.56BEF645@solibri.com>
Brian Seery wrote:

> Hi there I am totally new to lisp and lost, and I have a couple of
> questions. I am trying to write an immatation of ELIZA


> (defun doctor()
>   (defvar doctor nil)  ; this line is superfluous, you are not using a variable doctor
>   (let ((doctor nil)) 
  ; not doing anything with a local variable doctor here either, 
  ;; I'd define result and value here
>     (print '(speak up))
>     (print '>)
>     (do ((input (read) (read)))
>         ((endp input)
>          (print '(ok -- our time is up anyway))
>          (values))
>      (multiple-value-bind(result value)
>                          (doctor-tree input)
 As you are not doing anything with result, why are you
returning it?
>        (if value
>            (print value)
>            (progn
>              (print '(i did not understand that))
>              (print '(type nil if you want to stop)))))
>      (print '>))))



 Here you are using define-tree, which is not part of the
language, so you have to
 define it yourself. Your compiler has not seen a definition for
this yet.


> (define-tree doctor-tree
>              (brnchs(i am worried about * words if-end-rtn
>                        `(how long have you been worried about ,@words))))


 As you have not defined the macro define-tree, the system is
trying to run the normal   evaluation on its arguments, as it
hasn't been told otherwise.

 Remember that every time you use a macro, it has to have been
seen by the compiler 
 before you use it for anything. Was it possibly your next
top-level form after these?


> ;;;*** Warning in (TOP-LEVEL-FORM 2): DOCTOR-TREE assumed special
> ;;;*** Warning in (TOP-LEVEL-FORM 2): AM assumed special
> ;;;*** Warning in (TOP-LEVEL-FORM 2): WORRIED assumed special
> ;;;*** Warning in (TOP-LEVEL-FORM 2): ABOUT assumed special
> ;;;*** Warning in (TOP-LEVEL-FORM 2): WORDS assumed special
> ;;;*** Warning in (TOP-LEVEL-FORM 2): IF-END-RTN assumed special
> ;;;*** Warning in (TOP-LEVEL-FORM 2): WORDS assumed special
> ; (TOP-LEVEL-FORM 2)
> ; (TOP-LEVEL-FORM 3)
> ; (TOP-LEVEL-FORM 4)
> 
> The following functions are undefined:
> I which is referenced by (TOP-LEVEL-FORM 2)
> DEFINE-TREE which is referenced by (TOP-LEVEL-FORM 2)
> DOCTOR-TREE which is referenced by DOCTOR
> BRNCHS which is referenced by (TOP-LEVEL-FORM 2)


 These warnings would disappear if you had defined that
define-tree before using it.
 if doctor-tree is an ordinary function, you might still get a
warning about it, but it    can be safely ignored, if you get
around to defining it before you actually try to run 
 the function calling it.













--