8.5 Exports: export
By default, all of a module’s definitions are private to the module. The export form specifies definitions to be made available where the module is imported.
export_clause
....
An export form can only appear in a module body or a namespace body. Specifying multiple export_clauses in a single export is the same as using multiple export forms each with a single export_clause.
Each identifier can be exported at most once from a module across all exports within the module. More precisely, the external name for each export must be distinct; the same internal binding can be exported multiple times under different external names.
The simplest export_clause is just an identifier that names a binding within the module. The binding can be from either a local definition or from an import.
color
pi
The export form also can be combined with a definition to export the names defined by the definition:
export def color = "blue"
export fun greet(who):
"Hello, " ++ who
When a class or namespace is exported, bindings introduced by the
class or namespace—
Posn
class Posn(x, y)
exports Posn, Posn.x, Posn.y, and so on.
hue as color
export | |
| |
| |
export | |
"f2c.rhm" open
all_from("f2c.rhm")
The all_from form with .namespace_id re-exports everything that is exported by namespace_id, independent of the bindings that are imported or exposed from the namespace. A module import without open binds a namespace (based on the imported module’s name), so this form of all_from can be used to re-export all of the bindings of another module.
"f2c.rhm"
namespace extras:
export: def
"f2c.rhm" open
all_from("f2c.rhm"):
except fahrenheit_freezing