本文介绍了为什么 (require (for-syntax 'm)) 在 DrRacket 中执行所需模块中的表达式 3 次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何解释 DrRacket 的交互窗口中的以下行为.我认为输出应该只有一个hello",因为在这种情况下模块 m 应该被实例化一次.但实际上你好"打印了 3 次.

I don't know how to explain the following behavior in DrRacket's interactions window. I think the output should be only one "hello", since the module m should be instantiated once in this case. But actually "hello" is printed 3 times.

> (module m racket
    (printf "hello\n"))
> (module n racket
    (require (for-syntax 'm)))
hello
hello
hello
>

如果我在 DrRacket 的定义窗口中编写此示例并运行它,也会存在相同的行为.

The same behavior also exists if I write this example in DrRacket's definitions window and run it.

#lang racket

(module m racket
  (printf "hello\n"))

(module n racket
  (require (for-syntax (submod ".." m))))
hello
hello
hello
> 

此示例是 Racket 指南 (https://docs.racket-lang.org/guide/macro-module.html) -- 16.3.2 中的第一个例子.该文件中显示的行为很直观(打印一次字符串),但是当我在 DrRacket 的交互窗口中执行该代码时,它也会打印 3 次字符串.

This example is a simplified version of one from Racket's guide (https://docs.racket-lang.org/guide/macro-module.html) -- the first example in 16.3.2. The behavior shown in that documentis intuitive (printing the string one time), but when I execute that code in DrRacket's interactions window, it also prints the string 3 times.

我使用的是 DrRacket 7.7 版.

I'm using DrRacket version 7.7.

推荐答案

另见 https://github.com/greghendershott/racket-mode/issues/379https://github.com/racket/drracket/issues/278.

后者特别表明其中一个额外的来自 errortrace 检测,其中在 DrRacket 中默认开启.

The latter in particular indicates that one of the extra ones is from errortrace instrumentation, which is on by default in DrRacket.

这篇关于为什么 (require (for-syntax 'm)) 在 DrRacket 中执行所需模块中的表达式 3 次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 13:32