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

Viewed 76

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 Answers
Related