[plt-scheme] Attaching modules to namespaces in compiled code

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jan 26 07:46:24 EST 2009

At Mon, 26 Jan 2009 03:11:37 +0100, Jakub Piotr Cłapa wrote:
> The only-in/for-label require combination will take care of including 
> the module in the compiled binary?

Yes. The `require' sets up a dependency that pulls the module into the

> (why both? wouldn't an empty only-in 
> be sufficient?)

The empty `only-in' avoids introducing any bindings.

The `for-label' avoids tying execution of the enclosing module to
execution of the referenced module.

For example, suppose you have

  ;; stay.ss
  #lang scheme
  (printf "staying\n")
  (define result 'double)
  (provide result)

  ;; go.ss
  #lang scheme
  (printf "going\n")
  (define result 'trouble)
  (provide result)

  ;; letmeknow.ss
  #lang scheme
  (require scheme/runtime-path)

  (define-runtime-module-path s "stay.ss")
  (define-runtime-module-path g "go.ss")

  (let loop ()
    (case (read)
      [(cool-it) (dynamic-require s 'result)]
      [(blow) (dynamic-require g 'result)]
      [else (loop)]))


 1) An empty `only-in' is needed because "stay.ss" and "go.ss" both
    supply `result'.

 2) Using `for-label' avoids printing "staying" or "going" until after
    stdin supplies either "cool-it" or "blow".


Posted on the users mailing list.