I'm trying to figure out how to read a line from a file with guile scheme.
When I ask it to "read port" or "read-char port", it successfully reads.
guile -c '(let ((port (open-input-file "foo.txt"))) (display (read port)) (newline) (close-port port))'
But, when I ask it to read-line, it fails.
guile -c '(let ((port (open-input-file "foo.txt"))) (display (read-line port)) (newline) (close-port port))'
Does anyone know what I am doing wrong? I am currently in the directory where foo.txt is located.
Your code fails with the message ERROR: Unbound variable: read-line, meaning that there is no definition for readline.
The function read-line has to be loaded using the form (use-modules (ice-9 rdelim)) before you can use it. (https://www.gnu.org/software/guile/manual/html_node/Input-and-Output.html)
This will then work:
guile -c '(use-modules (ice-9 rdelim)) (let ((port (open-input-file "foo.txt")))
(display (read-line port)) (newline) (close-port port))'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With