From: ·········@gmail.com
Subject: n00b question
Date: 
Message-ID: <1104724157.045423.260010@f14g2000cwb.googlegroups.com>
Hi Everyone,
I'm working my through Paul Graham's "ANSI Common Lisp", and I've found
a code snippet that doesn't work as expected. It's on page 19, and it's
supposed to be a tidy little way to prompt the user and then return
their reply, unfortunately, when I run it, it seems to evaluate the
"(read)" function first, and then the format, resulting in a nasty
little bug. Can anyone tell me how this should work? Is my system using
some non-standard evaluation order, or should this just be rewritten?

I'm using: SBCL 0.8.15

The function is "ask-em", which evaluates thus:

* (defun ask-em (string)
(format t "~A" string)
(read))

ASK-EM
* (ask-em "How old are you?")

what?    <--------------------this is my input at the blinking cursor
How old are you?
WHAT?
*

Thanks for your help,
Ryan Kaulakis
From: Barry Margolin
Subject: Re: n00b question
Date: 
Message-ID: <barmar-05319A.23125802012005@comcast.dca.giganews.com>
In article <························@f14g2000cwb.googlegroups.com>,
 ·········@gmail.com wrote:

> Hi Everyone,
> I'm working my through Paul Graham's "ANSI Common Lisp", and I've found
> a code snippet that doesn't work as expected. It's on page 19, and it's
> supposed to be a tidy little way to prompt the user and then return
> their reply, unfortunately, when I run it, it seems to evaluate the
> "(read)" function first, and then the format, resulting in a nasty
> little bug. Can anyone tell me how this should work? Is my system using
> some non-standard evaluation order, or should this just be rewritten?
> 
> I'm using: SBCL 0.8.15
> 
> The function is "ask-em", which evaluates thus:
> 
> * (defun ask-em (string)
> (format t "~A" string)
> (read))
> 
> ASK-EM
> * (ask-em "How old are you?")
> 
> what?    <--------------------this is my input at the blinking cursor
> How old are you?
> WHAT?
> *
> 
> Thanks for your help,
> Ryan Kaulakis

Try calling FORCE-OUTPUT after the call to FORMAT.  I suspect that the 
output is being buffered.

Also, when you're asking questions and getting the answers, you should 
probably be using *QUERY-IO*.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***