[gambit-list] read-line

Joel J. Adamson jadamson at partners.org
Thu Apr 24 13:01:26 EDT 2008


Marc Feeley <feeley at iro.umontreal.ca> writes:

> On 24-Apr-08, at 12:24 PM, Joel J. Adamson wrote:
>
>> Marc Feeley <feeley at iro.umontreal.ca> writes:
>>
>>> On 24-Apr-08, at 10:47 AM, Joel J. Adamson wrote:
>>>
>>>> How the heck do I use read-line in a program?
>>
>> [...]
>>
>>>> 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 !
> I think I now understand your problem... you want to flush the input
> buffers so that the call to read-line will return only what was typed
> by the user after the moment of the call.  So here's one way to do it:
>
> (define (flush-input port)
>   (input-port-timeout-set! port 0.001)
>   (let loop () (if (not (eof-object? (read-line port))) (loop)))
>   (input-port-timeout-set! port +inf.0))

I see; it had not occurred to me to directly stall the port.  On top of that...

> (define (read-line-from-console)
>   (let ((port (console-port)))
>     (flush-input port)
>     (read-line port)))

I was unaware of console-port!  I was trying to find if there was a
"stdin-port" or "tty-port;" I guess (console-port) should have been my
next guess.

> (pp (read-line-from-console))

Excellent, that is exactly what I was going for.

Thank you!
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