Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!news.duke.edu!convex!cs.utexas.edu!howland.reston.ans.net!news.sprintlink.net!EU.net!uunet!sparky!kwiudl.kwi.com!usenet
From: tom@kwi.com (Tom Howland)
Subject: Re: Need help with streams under Quintus
In-Reply-To: mattc@leland.Stanford.EDU's message of 23 Oct 1994 23:19:57 GMT
Message-ID: <TOM.94Oct25113339@heather.kwi.com>
Lines: 28
Sender: usenet@kwiudl.kwi.com
Organization: KnowledgeWare Inc, Redwood City, CA 94065-1417
References: <38er2t$1bh@nntp.Stanford.EDU>
Date: Tue, 25 Oct 1994 18:33:39 GMT

>>>>> "Matthew" == Matthew William Clarke <mattc@leland.Stanford.EDU> writes:
In article <38er2t$1bh@nntp.Stanford.EDU> mattc@leland.Stanford.EDU (Matthew William Clarke) writes:


    Matthew> I am writing a program that reads from an input stream that
    Matthew> is updated at a rate that will be unknown to me.  I want to
    Matthew> be able to read up to the last character that has been
    Matthew> input so far (do a get0 on every character in the stream up
    Matthew> to the last), but I don't want to prompt for input past
    Matthew> that point (i.e., if a do a get0 after the end of the
    Matthew> input, I will be prompting for another character that will
    Matthew> not be there, and the program will halt until it receives
    Matthew> more input).  In other words, I need some way to find out
    Matthew> when I am at the end of what is currently in the stream.
    Matthew> Does anyone know of predicates I might use to do this?
    Matthew> BTW, if it matters, the streams I am reading from are TCP
    Matthew> connections, not the keyboard or files.

    Matthew> Thanks, -Matt Clarke mattc@leland.stanford.edu

If you're using the tcp package, you could use

non_blocking_get(Char) :-
    tcp_select_from(from(Socket), 0),
    tcp_input_stream(Socket, Stream),
    get0(Stream, Char).

which fails when there is no input available.
