[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sexp oriented select

From: Paul Jarc
Subject: Re: sexp oriented select
Date: Wed, 18 Jun 2003 17:32:55 -0400
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)

Ondrej Zajicek <address@hidden> wrote:
> My best idea is to use select, collect chars from ports, count
> parenthesis for each port and when something sexp-like appears then
> read it (from string created from collected chars)

Collect characters in a string buffer for each port.  After you append
some characters from the port, use something like the following
function to read an object from that string, and then replace the
buffer with the remaining characters.  Beware that this function does
not handle other kinds of read errors.

(define (pop-object buffer)
Read an object from BUFFER.  Return a pair of the object and the rest
of the buffer.  If BUFFER does not yet contain a complete object,
return #f."
   (lambda ()
     (define obj #f)
     (define exception #f)
     (catch 'misc-error
            (lambda () (set! obj (read)))
            (lambda exc (set! exception exc)))
     (if (and (list? exception)
              (equal? "end of file" (caddr exception)))
       (let loop ((new-buffer "")
                  (char (read-char)))
         (if (eof-object? char)
           (cons obj new-buffer)
           (loop (string-append new-buffer (make-string 1 char))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]