2017-05-23 10 views
0

저는 guile 체계를 사용하여 파일에서 한 줄을 읽는 방법을 알아 내려고하고 있습니다.파일에서 한 줄을 읽으십시오.

"읽기 포트"또는 "읽기 - char 포트"에 질문하면 성공적으로 읽습니다.

guile -c '(let ((port (open-input-file "foo.txt"))) (display (read port)) (newline) (close-port port))' 

하지만 읽기 전용으로 요청하면 실패합니다.

guile -c '(let ((port (open-input-file "foo.txt"))) (display (read-line port)) (newline) (close-port port))' 

내가 뭘 잘못하고 있는지 알아? 현재 foo.txt가있는 디렉토리에 있습니다.

답변

1

코드가 ERROR: Unbound variable: read-line 인 메시지와 함께 실패합니다. 즉, readline에 대한 정의가 없음을 의미합니다.

기능을 사용하려면 먼저 read-line(use-modules (ice-9 rdelim)) 양식으로로드해야합니다. (https://www.gnu.org/software/guile/manual/html_node/Input-and-Output.html)

이는 작동합니다

guile -c '(use-modules (ice-9 rdelim)) (let ((port (open-input-file "foo.txt"))) 
(display (read-line port)) (newline) (close-port port))'