On this page:
#%top

3.5 Variable References and #%top🔗ℹ

syntax

id

Refers to a top-level, module-level, or local binding, when id is not bound as a transformer (see Expansion). At run-time, the reference evaluates to the value in the location associated with the binding.

When the expander encounters an id that is not bound by a module-level or local binding, it converts the expression to (#%top . id) giving #%top the lexical context of the id; typically, that context refers to #%top. See also Expansion Steps.

Examples:
> (define x 10)
> x

10

> (let ([x 5]) x)

5

> ((lambda (x) x) 2)

2

syntax

(#%top . id)

Equivalent to id when id is bound to a module-level or top-level variable. In a top-level context, (#%top . id) always refers to a top-level variable, even if id is unbound or bound to syntax, as long as id does not have a local binding. In all contexts, (#%top . id) is a syntax error if id has a local binding.

Within a module form, (#%top . id) expands to just id as long as id is defined within the module and has no local binding in its context. At phase level 0, (#%top . id) is an immediate syntax error if id is not bound. At phase level 1 and higher, a syntax error is reported if id is not defined at the corresponding phase by the end of module-body partial expansion.

See also Expansion Steps for information on how the expander introduces #%top identifiers.

Examples:
> (define x 12)
> (#%top . x)

12

Changed in version 6.3 of package base: Changed the introduction of #%top in a top-level context to unbound identifiers only.
Changed in version 8.2.0.7: Changed treatment of locally bound id to always report a syntax error, even outside of a module.