EOF detection in binary using schema

(define (read-all-input)
  (local ((define line (bytes->list (read-bytes 4))))
    (if (eof-object? line)
        empty
        (cons line (read-all-input)))))

(void (read-all-input))

      

The above code does not work because bytes-> list expects a bytes string argument of type, but is assigned #

+2


source to share


2 answers


#lang scheme

(define (read-all-input)
 (let ((b (read-bytes 4)))
  (cond
   ((eof-object? b) empty)
   (else (cons b (read-all-input)))
)))

(void (read-all-input))

      



This function reads bytes into a list of bytes.

+3


source


I'm not really sure what you want to get, but this is my attempt here:



(define read-all-input
  (lambda ()
      (let ((line (read-bytes 4)))
        (if (eof-object? line)
            '()
            (cons (bytes->list line) (read-all-input))))))

      

0


source







All Articles