[gambit-list] read-line

Joel J. Adamson jadamson at partners.org
Thu Apr 24 10:47:40 EDT 2008


Hello,

Perhaps my previous message was too verbose, or there is someone still
trying it out.  After working on it some more, my question boils down to
this:

How the heck do I use read-line in a program?

Take the following REPL session as an example:

Gambit v4.2.6

> (read)
"This is an s-expression"  ;<=typed
"This is an s-expression"  ;<=echoed
> (read-line)
""
> (read-line)This is an s-expression
"This is an s-expression"
>

So, I know that I can call read-line from call-with-input-file, or
call-with-input-string, but if I have an input file or a string, then I
already have what I want.  What I want is for the user to input a line
of text, and for the program to do something with that line of text (as
a string).

However I use (read-line), it always accepts the text that was already
there (usually "" or "\t").  How do I get it (or some other procedure)
to accept user input?  What would I put into (call-with-input-string
... read-line)?  I've tried a few things, and I always just end up
redefining read-line:

> (define (read-this)
    (let ((input (read-char))
          (output ""))                 
      (if (char=? input #\newline) output
          (string-append (string input)
                         (read-this)))))
> (read-this)
""
> (read-this)this is text, baby
"this is text, baby"

I'm really not getting this; can someone please explain it to me?

Thanks,
Joel

-- 
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA  02114
(617) 643-1432
(303) 880-3109
Public key: http://pgp.mit.edu
http://www.unc.edu/~adamsonj

The information transmitted in this electronic communication is intended only
for the person or entity to whom it is addressed and may contain confidential
and/or privileged material. Any review, retransmission, dissemination or other
use of or taking of any action in reliance upon this information by persons or
entities other than the intended recipient is prohibited. If you received this
information in error, please contact the Compliance HelpLine at 800-856-1983 and
properly dispose of this information.






More information about the Gambit-list mailing list