Why does (require (for-syntax 'm)) execute expressions in the required module 3 times in DrRacket?

混江龙づ霸主 提交于 2021-01-04 07:38:05

问题


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
>

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
> 

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 document is intuitive (printing the string one time), but when I execute that code in DrRacket's interactions window, it also prints the string 3 times.

I'm using DrRacket version 7.7.


回答1:


See also https://github.com/greghendershott/racket-mode/issues/379 and https://github.com/racket/drracket/issues/278.

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



来源:https://stackoverflow.com/questions/63001494/why-does-require-for-syntax-m-execute-expressions-in-the-required-module-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!