() l...@gnu.org (Ludovic Courtès) () Sat, 11 Feb 2017 15:12:00 +0100 > (define (file->lines filename) > "Returns a list of lines contained in a file" > (call-with-input-file > filename > (lambda (p) > (let loop ([line (read-line p)]) > (if (eof-object? line) (list) > (cons > (substring line 0 (1- (string-length line))) > (loop (read-line p))))))))
UTF-8 I/O is usually faster in Guile 2.0. You might want to make sure your file is opened as UTF-8: (with-fluids ((%default-port-encoding "UTF-8")) (call-with-input-file file …)) FWIW, we can also use SRFI 13 to save a few cycles: (use-modules (ice-9 rdelim) (srfi srfi-13)) (define (file->lines filename) "Return a list of lines contained in a file." (call-with-input-file filename (lambda (p) (let loop ((acc '())) (let ((line (read-line p))) (if (eof-object? line) (reverse! acc) ; rv (loop (cons (string-drop-right line 1) acc)))))))) This variant is also more stack-conserving (amenable to TCO), which should afford some additional speedup. -- Thien-Thi Nguyen ----------------------------------------------- (defun responsep (query) (pcase (context query) (`(technical ,ml) (correctp ml)) ...)) 748E A0E8 1CB8 A748 9BFA --------------------------------------- 6CE4 6703 2224 4C80 7502
signature.asc
Description: PGP signature