LogoChemical Docs
Ctrl+K

Namespaces

Namespaces prevent name collisions by grouping related types and functions.

Declaring a Namespace

namespace Math {

    public func add(a : int, b : int) : int { return a + b }

}

Accessing Symbols

Use the :: operator to access members of a namespace.

var result = Math::add(5, 5)

Extending Namespaces

You can open the same namespace in multiple files or blocks to add more functionality. But you must keep the same access specifier

public namespace Math {}



// ❌ error: namespace Math's access specifier must match with existing namespace

namespace Math {}

The using Keyword

Tired of typing Math::? Use using to bring symbols into the current scope.

using namespace Math

var result = add(10, 10) // No Math:: needed!