From: s-76087
Subject: What is wrong with this function?
Date: 
Message-ID: <3739EAAB.314BFBBC@swipnet.se>
Hello,
I am trying to get input to make choices.
Here is:

(defun handling-input (sth)
   (read-line sth)
      (case (parse-integer sth)
   (1(print "case 1"))
   (2(print "case 2"))
   (3(print "case 3"))
   (otherwise (print "other cases"))))

For someone who knows what they are doing I guess it is simple.

Have a nice day/night

/Stefan

From: Barry Margolin
Subject: Re: What is wrong with this function?
Date: 
Message-ID: <fDm_2.667$jw4.45746@burlma1-snr2>
In article <·················@swipnet.se>,
s-76087  <···············@swipnet.se> wrote:
>Hello,
>I am trying to get input to make choices.
>Here is:
>
>(defun handling-input (sth)
>   (read-line sth)
>      (case (parse-integer sth)
>   (1(print "case 1"))
>   (2(print "case 2"))
>   (3(print "case 3"))
>   (otherwise (print "other cases"))))
>
>For someone who knows what they are doing I guess it is simple.

You seem to be very confused in the way you're using the parameter STH.  At
first you're supplying it as the stream argument to read-line, implying
that someone would so something like (handling-input *query-io*).  But then
you pass it to PARSE-INTEGER, which expects a string.  It looks like you're
expecting it to contain the return value of READ-LINE, even though you
never assigned it anywhere.  It would help if you used a more meaningful
variable name so that we could guess what you intended this to be.

I suspect what you want is something like:

(defun handling-input ()
  (let ((answer (read-line *query-io*)))
    (case (parse-integer answer)
      (1 (print "case 1"))
      (2 (print "case 2"))
      (3 (print "case 3"))
      (otherwise (print "other cases")))))

-- 
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: Thomas A. Russ
Subject: Re: What is wrong with this function?
Date: 
Message-ID: <ymi7lqdkljh.fsf@sevak.isi.edu>
s-76087 <···············@swipnet.se> writes:

> 
> Hello,
> I am trying to get input to make choices.
> Here is:
> 
>  (defun handling-input (sth)
>     (read-line sth)               ;; Line 1
>     (case (parse-integer sth)     ;; Line 2
>       (1 (print "case 1"))
>       (2 (print "case 2"))
>       (3 (print "case 3"))
>       (otherwise (print "other cases"))))

Presumably "sth" is bound to a stream of some sort.

In Line 1, you read a line from the stream.  The line is RETURNED as the
value of the read-line function, but since nothing is done with it, it
is essentially discarded.

In Line 2, you try to call the PARSE-INTEGER function on a stream.  It
would really like to have a string.

So, you need to make a connection between reading the line and parsing
the integer.

One solution is eliminate Line 1 and change Line 2 to be:

   (case (parse-integer (read-line sth))

This presents potential problems with end of file handling.  If one of
your cases was a quit case, you could set up the end of file value to
return a string encoding that case.  This is a clever solution, but
could lead to code maintenance problems -- the bane of most clever
solutions.

You should also consider what to do if parse-integer is given input that
isn't an integer.


-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu