我想在我的程序中有多个模块。例如。模块foo
和模块bar
。模块foo
将参考模块bar
。然后我希望能够在csi(解释)repl中测试这些模块。这个问题的根源在于如果我可以运行我的代码而不必编译它。以下是我的例子。解释多个模块
注:我是一个计划新手,所以这个代码可能有其他问题。随意指出任何事情,我会尽力纠正。
foo.scm
(use r7rs)
(define-library (foo)
(import (scheme base)
(prefix bar bar:))
(export add-some-stuff)
(begin
(define baz 1)
(define (add-some-stuff)
(+ baz bar:bork))
))
bar.scm
(use r7rs)
(define-library (bar)
(import (scheme base))
(export bork)
(begin
(define bork 2)))
结果更希望成为:
$ csi
> ,l foo.scm
> (import (prefix foo foo:))
> (foo:add-some-stuff)
;;=> 3
这是我得到的错误:
$ csi -q
#;1> ,l foo.scm
; loading foo.scm ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/r7rs.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/chicken.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/numbers.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/foreign.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/srfi-4.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/scheme.base.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/r7rs-support.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/extras.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/srfi-13.import.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/r7rs-compile-time.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/r7rs-library.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/r7rs-support.so ...
Note: re-importing already imported syntax: syntax-rules
Note: re-importing already imported syntax: cond-expand
Note: re-importing already imported syntax: define-record-type
Note: re-importing already imported syntax: include
Note: re-importing already imported syntax: include
Note: re-importing already imported syntax: import
Note: re-importing already imported syntax: import-for-syntax
Note: re-importing already imported syntax: cond-expand
Note: re-importing already imported syntax: import-for-syntax
Note: re-importing already imported syntax: import
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/r7rs.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/numbers.so ...
; loading /usr/local/Cellar/chicken/4.12.0/lib/chicken/8/scheme.base.so ...
Note: re-importing already imported syntax: syntax-rules
Note: re-importing already imported syntax: import-for-syntax
Note: re-importing already imported syntax: import
Note: re-importing already imported syntax: cond-expand
Note: re-importing already imported syntax: import-for-syntax
Note: re-importing already imported syntax: import
Error: (import) during expansion of (import ...) - cannot import from undefined module: bar
Call history:
numbers.scm:1672: scan-real
<syntax> (define-library (foo) (import (scheme base) (prefix bar bar:)) (export add-some-stuff) (begin (defin...
<syntax> (##core#module foo ((##r7rs#foo)) (##core#define-syntax ##r7rs#foo (##core#lambda _ (quote (##core#u...
<syntax> (##core#define-syntax ##r7rs#foo (##core#lambda _ (quote (##core#undefined))))
<syntax> (##core#lambda _ (quote (##core#undefined)))
<syntax> (##core#begin (##core#quote (##core#undefined)))
<syntax> (##core#quote (##core#undefined))
<syntax> (##core#undefined)
<syntax> (##sys#provide (##core#quote foo))
<syntax> (##core#quote foo)
<syntax> (import-for-syntax (only r7rs begin cond-expand export import import-for-syntax include include-ci s...
<syntax> (##core#undefined)
<syntax> (import (only r7rs begin cond-expand export import import-for-syntax include include-ci syntax-rules...
<syntax> (##core#undefined)
<syntax> (##core#begin (import (scheme base) (prefix bar bar:)) (##core#begin (export add-some-stuff) (##core...
<syntax> (import (scheme base) (prefix bar bar:)) <--
#;1>
感谢您的完整的答案!我的问题的根源在于我是否可以在我的项目中使用解释器而不必编译。看起来我不能,但也许这还没有确定性。我在我的例子中修复了其他错误。 –