On this page:
lazy-require

3.26 Importing Modules Lazily: lazy-require

The bindings documented in this section are provided by the racket/lazy-require library, not racket/base or racket.

syntax

(lazy-require [module-path (fun-import ...)] ...)

 
fun-import = fun-id
  | (orig-fun-id fun-id)
Defines each fun-id as a function that, when called, dynamically requires the export named orig-fun-id from the module specified by module-path and calls it with the same arguments. If orig-fun-id is not given, it defaults to fun-id.

If the enclosing relative phase level is not 0, then module-path is also placed in a submodule (with a use of define-runtime-module-path-index at phase level 0 within the submodule). Introduced submodules have the names lazy-require-n-m, where n is a phase-level number and m is a number.

When the use of a lazily-required function triggers module loading, it also triggers a use of register-external-module to declare an indirect compilation dependency (in case the function is used in the process of compiling a module).

Examples:
> (lazy-require
    [racket/list (partition)])
> (partition even? '(1 2 3 4 5))

'(2 4)

'(1 3 5)

> (module hello racket/base
    (provide hello)
    (printf "starting hello server\n")
    (define (hello) (printf "hello!\n")))
> (lazy-require
    ['hello ([hello greet])])
> (greet)

starting hello server

hello!