import
Symbol: import
Syntax:
Plain:
(import MODULE)– bind the root packageMember:
(import [MODULE as: BIND])– bind BIND to the leaf moduleRelative:
(import .MODULE),(import ..MODULE)(leading dots)
MODULE is an unquoted symbol whose printed name is the module name. Leading
dots indicate a relative import (level = number of dots).
Use-case: Import a module and bind it in the current namespace, mirroring
Python’s import statement.
Plain dotted import binds the root, Python-style:
(import foo.bar)bindsfoo, withfoo.barreachable as an attribute (foo.bar). The whole dotted chain is imported.The bracketed member form binds the leaf:
(import [foo.bar as: fbar])bindsfbarto thefoo.barsubmodule. The member uses the same[TARGET as: BIND]grammar asimport-from.Relative imports are always leaf-style:
(import .foo)binds the leaffoo. A bare relative import (dots only, no name) requires the member form and starts at two dots – a single lone dot is the reader’s dotted-pair marker and cannot be written in list syntax. To bind from the immediate parent package, name the module:(import .x).
Inline as: ((import foo as: bar)) is not supported; use the bracketed
member form.
Statement value: None.
Examples:
;; Plain dotted import -- binds 'foo' (root); foo.bar reachable as attribute
(import foo.bar)
;; Simple import -- binds 'os'
(import os)
;; Member form -- binds 'osp' to the leaf os.path
(import [os.path as: osp])
;; Relative import (one dot) -- binds leaf 'sibling'
(import .sibling)
;; Two-dot relative import -- binds leaf 'parent'
(import ..parent)
;; Bare relative (dots only) -- needs the member form
(import [.. as: parent-pkg])