2009-10-20 52 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)) 

该函数读取字节到字节的列表。