gambit scheme - import functions from another file into current scope

449 Views Asked by At

I have the function run in file run.scm. I want to make run available in test.scm. How would I go about doing this in Gambit scheme?

I've already tried (import "run.scm"), but it just complained about import being an unbound variable.

1

There are 1 best solutions below

0
On BEST ANSWER

Gambit Scheme uses include not import.

Gambit Scheme does not come with modules as standard, for modules like you seem to be describing, you would have to use 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, Which has a unique "external" module system, and is designed mainly for writing mobile applications.

So with files run.scm and test.scm in the same folder.......

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")))

then from the interpreter (gsi)

>(load "test.scm")

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

>(run)  ; output  -> no args

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