Repository navigation
Module Packages
A module name can resolve to a single file or a directory entry point:
app.shy
colors.shy
reports/
init.shy
summary.shy
import colors loads colors.shy. import reports loads reports/init.shy.
The importing script does not need to know which implementation was chosen.
If both reports.shy and reports/init.shy exist in one candidate directory,
loading is an ambiguity error. Import the package name, never reports::init.
A child can import its parent's public and private types with super. Public
functions and variables follow normal visibility; private non-type declarations
are not exposed by super.
reports/init.shy:
type InternalCount = Integer
pub import summary::{ describe }
reports/summary.shy:
import super::{ InternalCount }
pub fn describe($count: InternalCount): String { "count=${count}" }
main.shy:
import reports::{ describe }
echo (describe 9)
count=9
import super brings in the eligible parent interface; import super::{ Name }
selects names. Nested paths such as reports::summary resolve child modules.
pub import can make a child's selected names available through the parent.
For ordinary imports, search beside the importing module first, then each
colon-delimited directory in $SHELLY_MODULE_PATH, left to right. The first
matching candidate wins. Ordinary imports never consult $SHELLY_STD_PATH.
The reserved std:: prefix searches only standard-library locations. It never
uses the local-module rule or $SHELLY_MODULE_PATH. The prelude may itself be a
single file or a directory package; neither representation is assumed.
A module's resolved identity and cached scope are reused rather than repeatedly executing its source. See Startup and standard library for selection and reload behavior.
Related: Modules · Startup · Conditional code
Begin here
Values and expressions
- Language basics
- Variables and scope
- Numbers and logic
- Strings and paths
- Arrays
- Hash maps
- Ranges and iteration
- Control flow
- Match and type guards
Functions and types
- Functions and calls
- Closures and function types
- Methods and properties
- Structs
- Enums
- Named types and unions
- Conversions
- Types and properties
Shell and modules
- Pipelines
- Pipeline splits
- Pipeline formats
- Commands and exit status
- Redirection
- Environment and exported variables
- Modules and visibility
- Nested modules and directory packages
- Conditional imports and declarations
- Errors and cleanup
- Supervised processes and terminals
Library guides
- Standard library
- The implicit prelude
- Bytes, files, readers, and writers
- Explicit item streams
- JSON documents and typed mapping
- Sockets, DNS, and TLS
- HTTP clients
- HTTP servers
- Framing, server-sent events, and JSON-RPC
- Terminal colors, styles, and geometry
- Build an application console
Interactive use