[racket-dev] `configure-runtime' submodule

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue May 7 09:17:16 EDT 2013

When you run

 #lang racket
 '#(1 1 1)

the output is

 '#(1 1 1)

When you run 

 #lang scheme
 '#(1 1 1)

the output is

 #(1 1 1)

The difference in output (i.e., whether there's a leading quote) is
because the `racket' and `scheme' languages arrange different run-time
configuration of printing parameters. The language of a program's main
module determines the configuration that is used.

Until version, this run-time configuration was implemented via
the `#lang' reader, which attached a syntax property to the module,
which was preserved in the bytecode and accessed via
`module->language-info', which produced a vector that referred to
another module and a name of one of its exports, and so on... The
complex chain of indirections was designed to enable loading code for
different times at the right time --- but that's what submodules are

Now, command-line `racket', DrRacket, and `raco exe' look for a
`configure-runtime' submodule of a program's main module to be run
before the main module. This is a much simpler and more general way to
set up run-time parameters. For example, the output of

  #lang racket
  (module configure-runtime racket/base
    (print-vector-length #t))
  '#(1 1 1)



since the `configure-runtime' module above turns on vector lengths.

Normally, you don't write a `configure-runtime' submodule, and a
language's `#%module-begin' introduces a suitable declaration
automatically. The `racket' (and `racket/base') language adds a
`configure-runtime' submodule to a module body unless there's already
an immediate declaration (i.e., not under `begin' and not introduced by
a macro).

Besides being simpler to write and read, using a submodule is more
general than a reader-added property. I think Carl once asked for a way
to add runtime configuration at the macro level instead of the reader
level, and now that's available.

I haven't yet re-written the Guide's chapter 17 to use submodules, but
I'm planning to do that next.

Posted on the dev mailing list.