Modules: Name capture

Kris Kowal kris.kowal at
Wed Jun 2 12:34:41 PDT 2010

On Wed, Jun 2, 2010 at 12:14 PM, David Herman <dherman at> wrote:
> but if you have a module graph of N modules, and each needs to be
> explicitly linked with N - 1 other modules, then you impose a
> quadratic code-size requirement on programmers. Unless, as I said,
> you beef up your linking-specification language.

I agree that requiring explicit linking is a non-starter.  I do
however favor the option of explicit linking at some level of
granularity.  At reasonable expense, Narwhal provides several layers
at which someone can buy-into explicit linking:

* by manually instantiating a module using the module constructor
  proferred by the loader.

    var module = require.loader.load(id);

* by manually instantiating a module using a facility of the sandbox
  that provides the import and export facilities but a.) does not
  memoize the module and b.) permits additional free variables to be
  injected.  This is useful for creating module-enhanged "DSL's" that
  permit scripts designed for QUnit or Bogart to be migrated without
  alteration, subverting their use of global variables with explicitly
  injected free variables.

    require.once(id, freeVariables);

* by manually instantiating a system of modules with a preopopulated
  memo of module instances.

    var SANDBOX = require("narwhal/sandbox");
    var subRequire = SANDBOX.Sandbox({
        "modules": {
            "even": EVEN
    var EVEN = subRequire("odd");

I would invoke the axiom, "Simple should be easy, powerful should be
possible".  It's reasonable to pay for what you get.  At the risk of
misrepresenting their views, Ihab and Mark have argued that people
should always use explicit linking for a variety of reasons, but I for
one agree that implicit linking should be the norm, and explicit
linking can at least be deferred to the layer of "packages", or
coherently designed sets of modules linking to other coherently
designed sets of modules.  I presume that it is possible to isolate
and explicitly link groups of modules.

Kris Kowal

More information about the es-discuss mailing list