;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; io.scm ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (file->list fname) (let ((fin (open-input-file fname)) (l '())) (do ((x (read fin) (read fin))) ((eof-object? x) (close-input-port fin) l) (set! l (cons x l))))) ;;; ;;; Take the contents of file fname and ;;; deliver as a list ;;; (define (list->file l fname) (let ((fout (open-output-file fname))) (do ((ls l (cdr ls))) ((null? ls)) (let ((e (car ls))) (display e fout) (newline fout))) (close-output-port fout))) ;;; ;;; Write contents of a list to a file ;;; (define (write-random-data fname n m) (let ((fout (open-output-file fname))) (do ((i 1 (+ i 1))) ((> i n)) (display (+ 1 (random m)) fout) (display " " fout)) (close-output-port fout))) ;;; ;;; write stream of n random numbers to file ;;; where numbers are in the range 1 to m ;;; ;;; (list->file '(q w e r t y) "xxx") ;;; (file->list "xxx")