Skip to main content

Modules

RGC uses import to load modules, and public to control visibility.

Importing modules​

import geometry
import io

Defining a module​

# geometry.rg
public def area(w: float, h: float) -> float {
return w * h
}

# items without public are only visible inside the module
def helper() { ... }

Using a module​

import geometry

def main() {
print(geometry.area(3.0, 4.0))
}

Visibility​

  • public declarations (functions, types, constants) are visible outside.
  • Everything else is private by default, keeping implementation details inside module boundaries.

Standard library resolution​

import foo searches:

  1. foo.rg next to the entry file (project modules can override the standard library)
  2. RGC_STD (colon-separated directory list)
  3. lib/ and lib/rgc/ up to 4 parent directories of the compiler executable
  4. /usr/local/lib/rgc, /usr/lib/rgc

json, regex, string, list, path, net, udp, http, tls, https, and gzip are source modules under lib/; io, time, random, and os are compiler-provided virtual modules with no source file and cannot be overridden. Circular imports are compile errors.

Continue reading​