Require: Specifying package abbreviations

_Require_: Specifying package abbreviations

By Ryan Culpepper (ryanc at plt-scheme dot org)

Keywords: _require_, _module_, _package_, _library_


To use: (require (planet "" ("ryanc" "require.plt" 1 1)))

This module provides two macros for defining require-form abbreviations.
Both abbreviation-defining forms ('define-module' and 'define-library')
automatically provide the names that they define when used within a module.

> (define-module <name> <mod-spec> ...) SYNTAX

  Defines 'require-<name>' as a macro that expands into a require form
  for the given module spec(s).  Also defines 'require-for-syntax-<name>'
  and 'require-for-template-<name>'

    (define-module list (lib ""))
    ==Expands==> (require (lib ""))

    (define-module useful (lib "") (lib ""))
    ==Expands==> (require (lib "") (lib ""))

    (define-module test (planet "" ("schematics" "schemeunit.plt" 2)))
    ==Expands==> (require (planet "" ("schematics" "schemeunit.plt" 2)))

  When 'define-module' is given a relative module spec---that is, a relative
  path---the path is interpreted relative to the location of the 'define-module'
  form, *not* relative to the use of the require-abbreviation.

    (define-module util "")  ;; location A
    (require-util)                  ;; location B
    ==Expands==> (require (file "/<directory-of-location-A>/"))

  When given exactly one module spec, 'define-module' also defines
  'dynamic-require-<name>' as a procedure:

      (define-module list (lib ""))
      (dynamic-require-list 'filter)
    is equivalent to
      (dynamic-require '(lib "list") 'filter)

> (define-library <name> <package-spec>) SYNTAX

  Defines 'require-<name>' as a macro that expands into a require form
  for the given module spec, but taking the module (file) name and 
  optional additional subdirectories at the point of usage.

  Also defines 'require-for-syntax-<name>' and 'require-for-template-<name>'
  with analogous behavior.

  A package-spec is an absolute module spec (starting with lib, file, or planet)
  with the file part omitted.

    (define-library schemeunit (planet ("schematics" "schemeunit.plt" 1 2)))
    (require-schemeunit "")
    ==Expands==> (require (planet "" ("schematics" "schemeunit.plt" 1 2)))

    (define-library dr-priv (lib "drscheme" "private"))
    (require-dr-priv "")
    ==Expands==> (require (lib "" "drscheme" "private"))

    (define-library dr (lib "drscheme"))
    (require-dr "" "private")
    ==Expands==> (require (lib "" "drscheme" "private"))

    (define-library project (file "/home/schemer/project"))
    (require-project "")
    ==Expands==> (require (file "/home/schemer/project/"))

  Also defines 'dynamic-require-<name>' as a procedure:

      (define-library dr (lib "drscheme"))
      (dynamic-require-dr "" #f)
    is equivalent to
      (dynamic-require '(lib "" "drscheme") #f)


Projects that depend on external packages and collects may benefit from defining
shortcuts to those external resources in a single local module. This reduces the 
number of changes necessary when upgrading to a new version of a PLaneT package; 
the progammer must change the version numbers in one module rather than in every
module that uses that facility.

Expected usage:


(module config mzscheme
  (require (planet "" ("ryanc" "require.plt" 1)))
  (define-module foo (planet "" ("alice" "foo.plt" 3 2)))
  (define-library bar (planet ("bob" "bar.plt" 1 1)))))

;; require-foo, require-bar, etc are automatically exported

(module myfile mzscheme
  (require "")

(module myfile2 mzscheme
  (require "")
  (require-bar "")

When new versions of the 'bar.plt' package are available, the project
can switch to those by changing only the contents of the ""
file, rather than tracking down every occurrence of a require to
'bar.plt' in the project.