2009-10-20 76 views
2
(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)) 

因爲bytes->列表預計類型字節串的參數上面的代碼失敗,一個二進制文件,但是未給出#檢測EOF使用方案

回答

0

我真的不知道你想獲得什麼但這這裏是我的嘗試:

(define read-all-input 
    (lambda() 
     (let ((line (read-bytes 4))) 
     (if (eof-object? line) 
      '() 
      (cons (bytes->list line) (read-all-input)))))) 
3
#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)) 

該函數讀取字節到字節的列表。