• Re: read-byte and *standard-input*

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Mon Jul 7 19:28:06 2025
    From Newsgroup: comp.lang.lisp

    Rob Warnock wrote:

    > (with-open-stream (s (system:make-fd-stream
    (unix:unix-dup 0)
    :element-type '(unsigned-byte 8)))
    (loop for i = (read-byte s)
    collect i
    until (= i 10)))
    T: hello, there!
    (104 101 108 108 111 44 32 116 104 101 114 101 33 10)

    Gauche Scheme

    gosh> (collect-till b (read-byte) (= b 10))
    hello
    (104 101 108 108 111 13)
    gosh> (collect-till b (read-byte) (= b 10) #t)
    hello
    (104 101 108 108 111 13 10)


    Given:

    (define-syntax collect-till
    (syntax-rules ()
    [ (collect-till (x bag) expr test)
    (collect-till (x bag) expr test #f) ]
    [ (collect-till (x bag) expr test include-ender)
    (let go ((bag '()))
    (let ((x expr))
    (if test
    (if include-ender
    (reverse (cons x bag))
    (reverse bag))
    (go (cons x bag))))) ]
    [ (collect-till x expr test)
    (collect-till (x bag) expr test) ]
    [ (collect-till x expr test include-ender)
    (collect-till (x bag) expr test include-ender) ] ))
    --- Synchronet 3.21a-Linux NewsLink 1.2