Imports & Expose

TLang uses a simple path-based module system. expose makes a symbol callable by other files. use imports a module, making its exposed symbols available under an alias.

expose

expose declares which functions and templates are visible to other files. Symbols not listed with expose are private to the file.

      expose main
      expose greet
      expose entity

      func main(): String { ... }
      func greet(name: String): String { ... }
      func internal(): String { ... }   // NOT exposed — private

      lang [kotlin] entity(pkg: String, cls: String) { ... }
    

Multiple symbols are each declared on their own expose line.

use

use imports a file. The alias defaults to the last path segment (the filename without extension).

      use TLang.File          // alias: File  — standard library
      use TLang.Generator     // alias: Generator
      use TLang.List          // alias: List (also works as bare List.of(...))
      use helpers.Formatters  // alias: Formatters — from helpers/Formatters.tlang
      use Utils               // alias: Utils — from Utils.tlang in same directory
    

After importing, call exposed symbols via the alias.

      use helpers.StringUtils

      func main(): String {
          let slug = StringUtils.toSlug("Hello World")
          return slug
      }
    

Custom Aliases

Use as to give the import a different alias. Required when two imports have the same filename.

      use KotlinGen       as kotlin
      use JavaGen         as java
      use TypescriptGenerator as ts
      use lang.Overview   as LangOverview
      use stdlib.Overview as StdlibOverview
    

Generators need an alias that matches the lang template format name.

      use KotlinGen as kotlin

      lang [kotlin] entity(pkg: String, cls: String) {
          // format "kotlin" matches the alias
      }
    

Import Paths

Paths map to the filesystem relative to the project root (where manifest.yml lives). TLang.Module — standard library module. Always works regardless of project structure. File — imports File.tlang in the same directory as the importing file. folder.File — imports folder/File.tlang relative to the project root.

      use TLang.File         // standard library
      use TLang.Generator    // standard library
      use Utils              // ./Utils.tlang (same dir)
      use helpers.Math       // ./helpers/Math.tlang
      use models.Entities    // ./models/Entities.tlang
    

Maximum import depth is one subfolder level. Two-level paths like use a.b.File are rejected.

Visibility Rules

A symbol must be expose'd in its source file to be imported. Unexposed symbols are private. When you import a file, you access its exposed symbols via the alias.

      // helpers/Formatters.tlang
      expose toSlug
      expose capitalize

      func toSlug(s: String): String { ... }
      func capitalize(s: String): String { ... }
      func internalHelper(): String { ... }   // private
    
      // Main.tlang
      use helpers.Formatters

      func main(): String {
          let slug = Formatters.toSlug("Hello World")
          // Formatters.internalHelper()  ← would fail — not exposed
          return slug
      }
    

Standard Library Modules

All standard library modules are imported with use TLang.ModuleName. They are always available regardless of project structure.

      use TLang.File
      use TLang.Terminal
      use TLang.Generator
      use TLang.Leaf
      use TLang.List
      use TLang.Map
      use TLang.String
      use TLang.Math
      use TLang.Shell
      use TLang.Json
      use TLang.Yaml
      use TLang.Pdf
      use TLang.StringBuilder
      use TLang.Naming
      use TLang.Assert
      use TLang.Prompt
      use TLang.Formatting
    

TLang.Str is an alias for TLang.String — both work identically.