[gambit-list] read-line

Marc Feeley feeley at iro.umontreal.ca
Thu Apr 24 11:11:55 EDT 2008


On 24-Apr-08, at 10:47 AM, Joel J. Adamson wrote:

> 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?

I don't understand the problem you are having!  Your read-this is  
behaving exactly like read-line !

Marc




More information about the Gambit-list mailing list