在球拍中包含外部文件
答
您可以使用include
如下:
创建一个名为"foo.rkt"
文件看起来像这样:
(define x 1)
(define y 2)
在另一个文件
然后:
#lang racket
(require racket/include)
(include "foo.rkt")
(+ x y)
应该可以看到结果3
。
您也可以看到include
的文档。
答
要导出功能,一个模块的,你用provide
,考虑一个文件"foo.rkt"
:
#lang racket
(define fortytwo 42)
(define (det a b c)
(- (* b b) (* 4 a c)))
(provide (fortytwo det))
从
"foo.rkt"
文件"bar.rkt"
现在可以导入定义:
#lang racket
(require "foo.rkt")
(define (baz a b c)
(+ (det a b c) (- c 4)))
你的另一种方式可能允许其他文件访问文件中定义的所有内容,正在使用(all-defined-out)
:
#lang racket
(define fortytwo 42)
(define (det a b c)
(- (* b b) (* 4 a c)))
(provide (all-defined-out))
希望有所帮助。
答
你可以使用负载
(load "assert.scm")
还要注意有`include`,这可能是问题是什么原本约。 – 2011-01-27 03:34:25
不知何故,包括在我的情况下没有工作,但你的解决方案做的工作。 – dKab 2014-11-22 18:55:19