Namespaces
Bridje code is split into namespaces, one per file.
A namespace’s name is its path on the classpath, with . for /: todo.model is todo/model.brj.
In a Gradle project, sources are under src/main/bridje and tests under src/test/bridje.
A namespace is loaded the first time it’s required, and evaluated top to bottom, once. A definition can only refer to what’s defined above it.
The ns form
Section titled “The ns form”ns: name require: … import: …- Names the namespace, and declares what it uses. It must be the file’s first form; both clauses are optional.
ns: raft.server require: brj: as(concurrent, c) test raft: as(log, l) import: java.time: as(Instant, I) Durationrequire:- Bridje namespaces, grouped under a package prefix.
Within a prefix,
as(name, alias)requiresprefix.nameasalias; a barenamerequires it asname. import:- Host classes, grouped under a package prefix, in the same way:
as(Instant, I)importsjava.time.InstantasI. See host interop.
A namespace with no ns: form is anonymous.
Qualified names
Section titled “Qualified names”alias/name- A var, tag, enum or effect from a required namespace:
c/spawn,l/Entry{…}. alias/.key- A key from a required namespace.
full.ns.name/name- A var from a namespace by its full name, if it’s already loaded.
Alias/member,Alias/.member- A static or instance member of an imported class.
Unqualified names resolve to, in order: locals, the current namespace’s effects, brj.core’s effects, the current namespace’s definitions, brj.core’s definitions, imported classes, then host classes by their fully qualified name.
Running a namespace
Section titled “Running a namespace”A namespace that defines main can be run: main is called with the command-line arguments.
brj.main run namespace args…- Runs
namespace’smain, from the classpath.
In Gradle, the BridjeExec task does the same:
tasks.register<BridjeExec>("run") { mainNamespace = "hello.core" args("--port", "8080")}Privacy
Section titled “Privacy”There’s no access control: every definition in a namespace is visible to anything that requires it.
By convention, a name starting with _ is private.