import Statement
Overview
In Filtrera, the import
statement brings code from external modules into your script, making the module’s exported symbols accessible and enabling modular, reusable code.
Filtrera supports three main import forms, offering flexibility in how you bring external symbols into your script’s scope.
Important: All import
statements must appear in the root scope of the script (not inside blocks, functions, or any nested scope).
Syntax
1. Import All Exports Into Current Scope
import 'module'
- All exported symbols from
module
are made available directly in your script’s root scope, with no namespace prefix.
Example:
import 'math-constants'
from pifrom square 5
2. Import the Module as a Namespace Symbol
import myNamespace from 'module'
- All exported symbols become accessible as members of
myNamespace
.
Example:
import mathConstants from './math-constants.module.flt'
from mathConstants.pifrom mathConstants.square 5
3. Import Specific Named Exports
import { exportedSymbol1, exportedSymbol2 } from 'module'
- Brings only the listed symbols into your script’s root scope.
- You can assign an alias when importing, using
alias = exportedName
syntax.
Example:
import { pi, square } from './math-constants.module.flt'
from pifrom square 10
Example With Alias:
import { plus = add, times = multiply } from './math-ops.module.flt'
from 2 plus 3from 4 times 5
Example With Standard Module:
import { right = slice } from 'text'
from 'abcdef' right 3 // Returns 'def'
Usage Notes
- All
import
statements must be at the root scope. - Module identifiers must be static string literals.
- Importing the whole module by namespace protects your current scope from symbol collisions.
- Destructuring with aliases allows you to avoid naming conflicts or clarify intent.
- For details on loading custom modules, consult your host’s documentation, as path resolution and extension handling are host-dependent.
Summary Table
Syntax | Effect | Example Access |
---|---|---|
import 'module' | All exports into current scope | symbol |
import ns from 'module' | All exports under a new namespace symbol ns | ns.symbol |
import {a, b} from 'module' | Only exports a and b into current scope | a , b |
import {alias = exportedName} from 'module' | Export as alias in current scope | alias |
Examples
All Exports, No Namespace:
import 'math-constants'from pifrom square 2
Entire Module As Namespace:
import mathConstants from './math-constants.module.flt'from mathConstants.pifrom mathConstants.square 2
Some Exports, With and Without Aliases:
import { pi, square } from './math-constants.module.flt'from pifrom square 2
import { left = slice } from 'text'from left 'hello' 2 // 'he'
Additional Notes
- Import syntax is static and does not support runtime expressions.
- Refer to your host’s documentation for custom module path handling and naming conventions.