Subject: Re: What is char-ready? supposed to do?
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1996/11/21
Newsgroups: comp.lang.scheme
Message-ID: <5711bv$a64@tokyo.engr.sgi.com>

Peter E. Midford <pmidford@students.wisc.EDU> wrote:
+---------------
| The only system I have found that has a non-blocking char-ready? is
| MacGambit.  I've tried Macintosh ports of SCM and Gambit-C on both Unix
| (NetBSD 1.2) and Windows. Is this really a problem with the C run time
| library these implementations are using?
+---------------

Probably so. On the Unix versions of SCM & MzScheme compiled for Irix,
"char-ready?" is indeed non-blocking. That is, the following program
keeps looping until I type a line-feed -- it doesn't block:

      > (define (print . rest) (map display rest) (newline))
	  
      > (define (busy)
	  (read-char)           ;eat the line-feed that's waiting
	  (let loop ((i 0))
	    (cond
	      ((char-ready?)
	       (print "after looping " i " times, read: '" (read-line) #\'))
	      (else (loop (+ i 1))))))
      > (busy)
      xyz
      after looping 45871 times, read: 'xyz'
      > 


-Rob

p.s. Note that this is still using "line mode" terminal input, but that's
a property of the terminal driver, not Scheme. To have it wait for a single
charactor only, you'll have to do some system-dependent tweaking of the
terminal modes (e.g., "stty -icanon" or "stty cbreak" or "stty raw", etc.).

-----
Rob Warnock, 7L-551		rpw3@sgi.com
Silicon Graphics, Inc.		http://reality.sgi.com/rpw3/
2011 N. Shoreline Blvd.		Phone: 415-933-1673  FAX: 415-933-0979
Mountain View, CA  94043	PP-ASEL-IA