BSL(如何设计程序):如何将代码从单独的文件导入定义区域? [英] BSL (How to Design Programs): how to import code from a separate file into definitions area?

查看:37
本文介绍了BSL(如何设计程序):如何将代码从单独的文件导入定义区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 BSL 问题.我想将我的代码分成单独的辅助文件并使用

I'm having an issue with BSL. I want to divide my code into separate auxiliary files and use

(require "auxiliary-function.rkt") 

在开始时将分离的代码导入定义区域.然而,它并没有像预期的那样工作.虽然没有给出明确的错误,但 DrRacket 似乎根本没有看到单独文件中的代码,我看到的只是错误

at the beginning to import the separated code into the definitions area. However it doesn't work as supposed. Though no explicit error given, it seems like that that DrRacket simply doesn't see the code in the separate file and all I see is the error

<auxiliary-function-name>: this function is not defined 

显然,

(provide x)

不包含在 BSL 中.我已经阅读了 手册this 答案,但目前尚不清楚如何进行这项工作.这在 BSL 中甚至可能吗?

is not included in BSL. I've read the manual and this answer but it’s still not clear how to make this work. Is this even possible in BSL?

谢谢!

推荐答案

请注意,如果您正在为课程执行此操作,则此策略可能不会被接受.

Note that if you're doing this for a course this strategy might not be accepted for a submission.

我为自己的一些项目所做的就是这样的模式:

What I have done for some of my own projects is a pattern like this:

有一个用普通 Racket 编写的文件,名为 "provide.rkt",如下所示:

Have one file written in plain Racket, called "provide.rkt", like this:

; provide.rkt
#lang racket
(provide provide all-defined-out)

然后您可以使用它来提供特定功能或提供文件中的所有定义.

Then you can use this to either provide specific functions or provide all definitions from a file.

在您的库"BSL 文件中,您可以像这样要求提供,并使用它来提供您想要的特定功能:

In your "library" BSL file, you can require provide into it like this, and use that to provide the specific function(s) you want:

; <auxiliary-library>.rkt
; written in BSL
(require "provide.rkt")

(provide <auxiliary-function-name>)

(define (<auxiliary-function-name> ....) ....)

最后,在您的主"BSL 文件中,您可以像这样要求库:

And finally, in your "main" BSL file, you can require the library like this:

; written in BSL
(require "<auxiliary-library>.rkt")

(<auxiliary-function-name> ....)

用于提供文件中的所有定义

在您的库"BSL 文件中,您可以要求提供并使用它来提供所有内容:

For providing all definitions from a file

In your "library" BSL file, you can require provide into it and use that to provide everything:

; <auxiliary-library>.rkt
; written in BSL
(require "provide.rkt")

(provide (all-defined-out))

(define (<auxiliary-function-name-1> ....) ....)

(define (<auxiliary-function-name-2> ....) ....)

...

然后在您的主"BSL 文件中,您可以要求该库并获取所有定义:

Then in your "main" BSL file, you can require the library and get all of the definitions:

; written in BSL
(require "<auxiliary-library>.rkt")

(<auxiliary-function-name-1> ....)

(<auxiliary-function-name-2> ....)

...

这篇关于BSL(如何设计程序):如何将代码从单独的文件导入定义区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆