gambit scheme - 从另一个文件导入函数到当前作用域

gambit scheme - import functions from another file into current scope

我在文件 run.scm 中有函数 run。我想让 runtest.scm 中可用。我将如何在 Gambit 方案中执行此操作?

我已经尝试过 (import "run.scm"),但它只是抱怨 import 是一个未绑定的变量。

Gambit Scheme 使用 include 而不是 import

Gambit Scheme 没有标准模块,对于像你描述的模块,你必须使用 Black hole, which is an extension of Gambit and needs to be installed and loaded separately or Gerbil Scheme which is built on gambit (so is nearly as fast I guess though I have never used it). Another scheme based on Gambit Scheme with modules is LambdaNative,它有一个独特的 "external" 模块系统,并且被设计主要用于编写移动应用程序。

因此,文件 run.scmtest.scm 在同一文件夹中......

run.scm

(define (run .  args)
  (if (not (null? args)) 
      ( println args) 
      ( println "no args")))

test.scm

(include "run.scm")

(define (test-run . args)
  (if (not (null? args))
      (run args )   
      (println "run not tested")))

然后来自解释器 (gsi)

>(load "test.scm")

>(test-run 1 2 3)  ; output  -> 123

>(run)  ; output  -> no args

>(test-run) ; output ->  run not tested