"Module not found" 诡计多端

"Module not found" in Guile

我正在 Guile 上为 "Gnubik" 程序编写扩展脚本,当我尝试使用 "textual-ports" 模块中的函数 "get-string-all" 时出现 "module not found" 错误:当我从命令行启动 Gnubik,打印错误文本并且程序不启动。在 Guile shell 脚本中使用此函数时 - 此问题不会发生。我安装了两个 Guile 包:2.0 和 2.2。

错误文本如下:

Backtrace:
In ice-9/boot-9.scm:
 160: 10 [catch #t #<catch-closure c86380> ...]
In unknown file:
   ?: 9 [apply-smob/1 #<catch-closure c86380>]
In ice-9/eval.scm:
 505: 8 [#<procedure b5e540 at ice-9/eval.scm:499:4 (exp)> (use-modules #)]
In ice-9/psyntax.scm:
1107: 7 [expand-top-sequence ((use-modules (ice-9 textual-ports))) () ...]
 990: 6 [scan ((use-modules (ice-9 textual-ports))) () ...]
 279: 5 [scan ((# #) #(syntax-object *unspecified* # #)) () (()) ...]
In ice-9/boot-9.scm:
3622: 4 [process-use-modules (((ice-9 textual-ports)))]
 712: 3 [map #<procedure c1ab40 at ice-9/boot-9.scm:3622:25 (mif-args)> ((#))]
3623: 2 [#<procedure c1ab40 at ice-9/boot-9.scm:3622:25 (mif-args)> (#)]
2903: 1 [resolve-interface (ice-9 textual-ports) #:select ...]
In unknown file:
   ?: 0 [scm-error misc-error #f ...]

ERROR: In procedure scm-error:
ERROR: no code for module (ice-9 textual-ports)

诡计代码:

(use-modules (ice-9 textual-ports))

(call-with-input-file "/tmp/tst.txt" 
    (lambda (port)
        (define s (get-string-all port))))

如何解决这个问题?

根据文档“(use-modules (rnrs io ports))”。

适合我。

编辑:在查看 guile-2.0 时,我看到 get-string-all 由“(rnrs io ports)”模块提供,但在 guile-2.2 中它由“(rnrs io ports)”和“(ice-9 textual-ports)”模块提供。

所以有两个问题。首先,您试图在 guile-2.0 中加载“(ice-9 textual-ports)”模块,这不会起作用,因为它仅由 guile-2.2 提供。其次,你的lambda形式没有表达式,只需要return应用get-string-all的值