我目前正在研究一组用 Chicken Scheme 编写的实用程序,这是我第一次尝试在 Chicken Scheme 中编写基于多文件的程序(或一组程序),我遇到了一些麻烦弄清楚如何正确使用附件文件中定义的代码,以便在编译所有内容时,文件中定义的代码A
将可以被编译后的文件形式访问B
。我基本上需要 Chicken Scheme 的等效于以下 C 代码:
#include "my_helper_lib.h"
int
main(void)
{
/* use definitions provided by my_helper_lib.h */
return 0;
}
我已经尝试使用以下所有方法,但它们都产生了各种不寻常的错误,例如:'()
未定义,这没有意义,因为'()
只是另一种写作方式(list)
。
;;; using `use`
(use "helper.scm") ;; Error: (require) cannot load extension: helper.scm
;;; using modules
;; helper.scm
(module helper (foo)
(import scheme)
(define foo (and (display "foobar") (newline))))
;; main.scm
(import helper) ;; Error: module unresolved: helper
;;; using `load`
(load helper.scm) ;; Error: unbound variable: helper.scm
(load "helper.scm") ;; Error: unbound variable: use
;; note: helper.scm contained `(use scheme)` at this point
;; using `require`
(require 'helper.scm) ;; Error: (require) cannot load extension: helper.scm