【问题标题】:Read a line from a file从文件中读取一行
【发布时间】:2017-10-23 22:57:20
【问题描述】:

我正在尝试弄清楚如何使用 guile 方案从文件中读取一行。

当我要求它“读取端口”或“读取字符端口”时,它读取成功。

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 所在的目录中。

【问题讨论】:

    标签: guile


    【解决方案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))'
    

    【讨论】:

      猜你喜欢
      • 2013-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2017-04-03
      • 1970-01-01
      • 2017-06-28
      相关资源
      最近更新 更多