导入模块(特别是guile)的scheme语法是什么?

导入模块(特别是guile)的scheme语法是什么?,scheme,lisp,guile,Scheme,Lisp,Guile,如何在Scheme中导入模块(特别是guile) 如何在scheme中创建模块并将其导入到另一个脚本中?导入模块时应该如何编译脚本,必须传递哪些命令行参数?如果模块位于另一个目录中,如何导入该模块?让我们创建一个模块test\u module.scm,其中包含以下代码,其位置为/some/dir 在这里,我们使用以下语法创建了一个模块: (define-module (name-of-the-module) #: export (function1-to-be-exported

如何在Scheme中导入模块(特别是guile)

如何在scheme中创建模块并将其导入到另一个脚本中?导入模块时应该如何编译脚本,必须传递哪些命令行参数?如果模块位于另一个目录中,如何导入该模块?

让我们创建一个模块test\u module.scm,其中包含以下代码,其位置为/some/dir

在这里,我们使用以下语法创建了一个模块:

(define-module (name-of-the-module)
    #: export (function1-to-be-exported
               function2-to-be-exported))
;; rest of the code goes here for example: function1-to-be-exported
(use-modules (name-of-the-module))
;; now all the functions that were exported from the 
;; module will be available here for our use
现在,让我们创建一个脚本,用于导入我们创建的名为use_module.scm的模块,其中包含此代码,位于当前目录中

(use-modules (test_module))
(format #t "~a\n" (square 12))
在这里,我们使用了以下语法的模块:

(define-module (name-of-the-module)
    #: export (function1-to-be-exported
               function2-to-be-exported))
;; rest of the code goes here for example: function1-to-be-exported
(use-modules (name-of-the-module))
;; now all the functions that were exported from the 
;; module will be available here for our use
现在让我们进入编译部分,我们必须将GUILE_LOAD_PATH设置为location/some/dir,然后编译脚本

现在,假设test_module.scm和use_module.scm都位于同一目录中,然后执行以下操作:

$ GUILE_LOAD_PATH=. guile use_module.scm
但是,如果模块位于/some/dir中,通常会执行此操作:

p、 更简单的方法是编写脚本,使用addtoload路径告诉guile模块的位置。现在我们可以编译而不用担心环境变量

(add-to-load-path "/some/dir")
(use-modules (name-of-the-module))
;; rest of the code

我创建了一个模块test\u module.scm()和一个脚本use\u module.scm()。模块和脚本都在同一目录中。我尝试使用命令“guile use_module.scm”运行脚本。我得到这个错误,就我所能理解的脚本是无法访问模块。请帮帮我。我从IRC的人那里得到了帮助,我学会了怎么做。