diff options
| author | 2025-06-17 15:00:10 -0400 | |
|---|---|---|
| committer | 2025-06-17 15:00:10 -0400 | |
| commit | 873c559b81e79a2fd7570e5be9ebbc49776d3eaa (patch) | |
| tree | 6ec5703fff468bff04f066fd5634557839752d72 | |
| parent | README: fix more typos (diff) | |
initialize all elements to 0; make work on R4RS
| -rw-r--r-- | bf2s.scm | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -69,15 +69,17 @@ (define (brainfuck->scheme-from-file filename) (brainfuck->scheme - (call-with-port (open-input-file filename) - (lambda (port) - (let loop ((str "")) - (if (eof-object? (peek-char port)) - str - (loop (string-append str (read-line port))))))))) + (with-input-from-file filename + (letrec ((loop + (lambda (chars) + (let ((next (read-char))) + (if (eof-object? next) + (list->string (reverse chars)) + (loop (cons next chars))))))) + (lambda () (loop '())))))) (define (execute scheme len) - ((eval scheme) (make-vector len) 0 + ((eval scheme) (make-vector len 0) (inexact->exact (floor (/ len 2))) (lambda (data dptr) (display (list data dptr)) (newline)))) |
