如何在模块内部使用模块?

时间:2014-07-08 21:07:19

标签: module rebol rebol3

我有这个简单的模块:

REBOL[
    Name: 'test1
    Type: 'module
    Exports: [foo]
]

foo: does [print "foo"]

和这一个:

REBOL[
    Name: 'test2
    Type: 'module
    Exports: [bar]
]

import %test1.reb

foo

bar: does [foo]

当我尝试import %test2.reb时,我收到foo word is not bound to a context错误。 出现此错误后,我可以从控制台调用foo,因此导入了它,但不知怎样它对test2模块是不可见的。那么在模块内部使用模块的正确方法是什么?

2 个答案:

答案 0 :(得分:2)

我不确定这是IMPORT中的错误,但是使用NEEDS标题应该有效:

Rebol [
    Name: 'test2
    Type: 'module
    Exports: [bar]
    Needs: [%test1.reb]
]

foo

bar: does [foo]

答案 1 :(得分:0)

您可以将单词设置为导入返回

REBOL[
    Name: 'test2
    Type: 'module
    Exports: [bar]
]

t1: import %test1.reb

t1/foo

bar: does [t1/foo]

修改

我尝试使用'do,并且它已经工作了,但现在我无法重现它。所以也许还有其他事情发生,或者我在重试之前忘了关闭控制台。