On this page:
import
/
.
lib
file
!
self
parent
as
open
expose
rename
only
except
meta
meta_  label
only_  meta
only_  meta_  label
only_  space
except_  space
#%juxtapose
Module  Path
Module  Path
Module  Path.s_  exp
8.12

6.4 Import🔗ℹ

definition

import:

  import_clause

  ...

 

definition

import import_clause

 

import_clause

 = 

import_item

 | 

import_item:

  modifier

  ...

 | 

import_item modifier

 | 

import_item modifier:

  modifier

  ...

 | 

modifier:

  import_clause

  ...

 

import_item

 = 

module_path

 | 

import_item #%juxtapose import_item

 | 

other_import_item

 

module_path

 = 

collection_module_path

 | 

string

 | 

lib(string)

 | 

file(string)

 | 

module_path ! id

 | 

. id

 | 

module_path . id

 | 

module_path . (op)

 | 

self ! id

 | 

parent ! ...

 

collection_module_path

 = 

id

 | 

id / collection_module_path

 

modifier

 = 

as id

 | 

as ~none

 | 

open open_decl

 | 

expose expose_decl

 | 

rename rename_decl

 | 

only only_decl

 | 

except except_decl

 | 

meta meta_decl

 | 

meta_label

 | 

only_meta meta_decl

 | 

only_meta_label

 | 

only_space only_space_decl

 | 

except_space except_space_decl

 | 

other_modifier

Imports into the enclosing module or block. An import form with a single immediate import_clause is a shorthand for an import form that has a block containing the single import_clause.

The import_clause variant import_item or import_item: modifier; ... are the canonical forms. The other import_clause forms are converted into a canonical form:

An import_item is typically a module_path, but it can be a juxtaposed combination of parsed module_paths, or it can be another import clause form defined with impo.macro.

By default, each clause with a module_path binds a prefix name that is derived from the module_path’s last element. Imports from the module are then accessed using the prefix, ., and the provided-provided name. The as modifier with an identifier supplies a prefix to use, instead, while the as modifier with ~none indicates that only exposed names should be bound.

A module_path clause can be be adjusted through one or more modifiers. The set of modifiers is extensible, but includes as, rename, and expose.

A module_path references a module in one of several possible forms:

As a module-path operator, combines id and collection_module_path to build a longer collection-based module path.

As an module-path operator, a prefix . refers to an import prefix or a namespace id in the enclosing environment, and an infix . refers to an id or op provided by collection_module_path.

import

lib(string)

Refers to an installed collection library, where string is the library name. See import for more information.

import

file(string)

Refers to a file through a platform-specific path, where string is the library name. See import for more information.

import

module_path ! id

Refers to a submodule name id of the module referenced by module_path. See import for more information.

import

self ! id

 

import

parent

 

import

parent ! ...

The form self!id refers to submodule named id of the enclosing module. Additional uses of ! refer to more deepely nested submodules within that one.

In an interactive context, such as a read-eval-print loop (REPL), self!id refers to a module declaraed interactively with name id.

The form parent refers to the parent of an enclosing submodule. A parent form may be followed by !id to access a submodule of the enclosing module (i.e., a sibling submodule). When additional additional ! operators are used before an id or without a subsequent id, each ! refers to an enclosing parent, thus reaching an ancestor module.

See import for more information.

import modifier

as id

 

import modifier

as ~none

Modifies an import clause to bind the prefix id, used to access non-exposed imports, instead of inferring a prefix identifier from the module name. When as is followed by ~none instead of id, then no prefix is bound for the import (so only exposed identifiers are bound).

import modifier

open

 

import modifier

open ~scope_like id

Modifies an import clause so that no prefix (normally based on the module name) is bound, and all imports are implicitly exposed. Contrast with as ~none, which also binds no prefix, but binds only names that are speficially exposed.

If ~scope_like id is specified, then the name part of id does not matter, but its scopes are used for the exposed bindings. Otherwise, the scopes for each exposed binding is defived from the module or namespace specification that this open form modifies.

import modifier

expose id_or_rename_as

 

import modifier

expose:

  id_or_rename_as

  ...

 

id_or_rename_as

 = 

id

 | 

rename_as

Modifies an import clause so that the listed ids are imported without a prefix. The exposed ids remain accessible though the import’s prefix, too.

If as is used, the id is renamed in addition to being exposed, or in other words, it behaves like a combination of rename and expose.

import modifier

rename rename_as

 

import modifier

rename:

  rename_as

  ...

 

rename_as

 = 

id as local_id

Modifies an import clause so that local_id is used in place of the imported id name id. The new name local_id applies to modifiers after the rename modifier.

import modifier

only id

 

import modifier

only:

  id ...

  ...

Modifies an import clause so that only the listed ids are imported.

import modifier

except id

 

import modifier

except:

  id ...

  ...

Modifies an import clause so that the listed ids are not imported.

import modifier

meta

 

import modifier

meta phase

Modifies an import clause so that the imports are shifted by phase levels, where phase defaults to 1.

This modifier is valid only for module paths that refer to modules, as opposed to namespace bindings, and it is not currently supported for module paths that use the . operator.

import modifier

meta_label

Modifies an import clause so that only the imports that would be at phase 0 are imported, and they are imported instead to the label phase.

This modifier is valid only for module fies that refer to modules, as opposed to namespace bindings, and it is not currently supported for module paths that use the . operator

import modifier

only_meta phase

 

import modifier

only_meta_label

Modifies an import clause so that only imports exported at the indicated phase are imported.

This modifier is valid only for module paths that refer to modules, as opposed to namespace bindings, and it is not currently supported for module paths that use the . operator unless phase is 0.

import modifier

only_space id

 

import modifier

only_space: id ...

 

import modifier

except_space id

 

import modifier

except_space: id ...

Modifies an import clause to include bindings only in the specifically listed spaces or only in the spaces not specifically listed.

Imports the union of modules described by the two import_items. This form is typically useful only to create parsed import forms, because parsing will otherwise attempt to treat juxtaposed sequences as an import and modifier.

The #%juxtapose form is implicitly used when an import is used in after another import in an import position. See also Implicit Forms.

annotation

ModulePath

 

function

fun ModulePath(mod_stx :: Group) :: ModulePath

 

expression

ModulePath 'module_path'

 

function

fun ModulePath.s_exp(modmath :: ModulePath) :: Any

The ModulePath annotation recognizes values that represent module paths, and the ModulePath function and expression form create such a value for a syntax-object mod_stx or a quoted module_path.

The format of a module_path or the content of mod_stx is the same as for import, except that . is supoprted only at the very beginning of a module path in ModulePath.

The ModulePath expression form (which has immediate quotes instead of a parenthesized argument expression) statically checks that module_path is well-formed, while the ModulePath funciton can check only when it is called. In both cases, however, the generated module path is relative to the top-level environment, not the enclosing context.

The ModulePath.s_exp function produces the Racket form of a Rhombus module path, which is suitable for use with Racket functions that expect a module path.