[racket] nested require modules and global variable

From: Niitsuma Hirotaka (hirotaka.niitsuma at gmail.com)
Date: Sat Dec 17 17:16:37 EST 2011

Is this valid behavior?

-----sub-sub.scm------
#lang racket
(provide  my-global-var print-my-global-var set-my-global-var!)
(define my-global-var "global in sub-sub")
(define (print-my-global-var) (display my-global-var) (newline))
(define (set-my-global-var! v) (set! my-global-var v))
-------------------------

-----sub.scm------
#lang racket
(provide  set-my-global-var-in-sub print-my-global-var-in-sub)
(require "sub-sub.scm")
(define (set-my-global-var-in-sub) (set-my-global-var! "in sub"))
(define (print-my-global-var-in-sub)
-------------------------


--------main.scm-----------------
#lang racket

(require "sub.scm")
(require "sub-sub.scm")

(display  my-global-var)(newline)
(print-my-global-var-in-sub)
(print-my-global-var)

(set-my-global-var! "call sub sub")

(display  my-global-var)(newline)
(print-my-global-var-in-sub)
(print-my-global-var)

(set-my-global-var-in-sub)

(display  my-global-var)(newline)
(print-my-global-var-in-sub)
(print-my-global-var)
-------------------------

$racket main.scm

global in sub-sub
global in sub-sub
global in sub-sub
call sub sub
call sub sub
call sub sub
in sub
in sub
in sub


Posted on the users mailing list.