重新定义 r6rs 中的语法关键字

发布于 2024-09-10 16:08:18 字数 950 浏览 2 评论 0原文

如何创建一个名为 rnrs-modified 的库,它将使以下代码显示“Hello, world!”...?

#!r6rs
(import (rnrs-modified))
(display set!)

或者甚至这会很好(实际上可以说更好):

#!r6rs
(import (rnrs) (modified)) ;or (import (modified) (rnrs))
(display set!)

本质上我希望能够在库中重新定义语法关键字(let、lambda、set!等),然后将该库导入到另一个库或顶级库中编程并使用那些重新定义的关键字。

然而我不断收到这样的消息:

module: identifier already imported from a different source in:
  set!
  (lib "rnrs/main.ss")
  (lib "rnrs-modified/main.ss")

我用于 rnrs-modified 的代码是:

#!r6rs
(library (rnrs-modified)
         (export (rename (f set!)))
         (import (rnrs))
         (define f "Hello, world!"))

有什么想法吗?


更新:我发现这个用于'mzscheme模块'。它不适用于 r6rs 方案,但它提供的功能基本上正是我正在寻找的。如何在 r6rs 方案中提供 all-from- except

How can I create a library called rnrs-modified which will make the following code display "Hello, world!"...?

#!r6rs
(import (rnrs-modified))
(display set!)

or even this would be good (arguably better, actually):

#!r6rs
(import (rnrs) (modified)) ;or (import (modified) (rnrs))
(display set!)

Essentially I want to be able to redefine syntactic keywords (let, lambda, set!, etc) in a library, and then import that library into another library or a top-level program and use those redefined keywords.

However I keep getting this:

module: identifier already imported from a different source in:
  set!
  (lib "rnrs/main.ss")
  (lib "rnrs-modified/main.ss")

The code I'm using for rnrs-modified is:

#!r6rs
(library (rnrs-modified)
         (export (rename (f set!)))
         (import (rnrs))
         (define f "Hello, world!"))

Any ideas?


Update: I found this for 'mzscheme modules'. It's not for r6rs scheme, but the functionality it offers is basically exactly what I'm looking for. How can I do provide all-from-except in r6rs scheme?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2024-09-17 16:08:18

R6RS 通过识别您想要自定义的库、排除您想要自定义的部分,然后在您自己的库中定义这些部分,更有助于实现您的目标。下面是一个例子:

myrnrs.sls

(library
 (myrnrs)

 (export set!)

 (import
  (except (rnrs) set!)
  (rename (rnrs) (set! rnrs-set!)))

 (define set! "Hello, world."))

test.scm

(import
 (except (rnrs) set!)
 (myrnrs))
 (display set!)(newline)    

不幸的是,没有像我们在 Racket 中那样的 all-from- except ;因此您可以创建一个重新定义 set! 的库,但除了重新定义 set! 之外,您还必须导入 rnrs,然后输入所有这些绑定的导出。您可以在此处了解更多相关信息;讽刺的是,我也想创建一个没有设置的库!

R6RS lends itself more towards achieving your goal by identifying the library that you want to customize, excluding the parts you want to customize, and then defining those parts in your own library. Here is an example:

myrnrs.sls

(library
 (myrnrs)

 (export set!)

 (import
  (except (rnrs) set!)
  (rename (rnrs) (set! rnrs-set!)))

 (define set! "Hello, world."))

test.scm

(import
 (except (rnrs) set!)
 (myrnrs))
 (display set!)(newline)    

Unfortunately there is nothing like all-from-except like we have in Racket; so you could create a library that redefines set!, but you would have to import rnrs and then type in the exports for all of those bindings in addition to redefining set!. You read more about here; ironically I wanted to create a library without set!, too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文