AutolangDocs

Magic Constants

Autolang provides special compiler-resolved constants that change their value depending on where they are used. Unlike normal variables, these are replaced with their actual values at compile time, meaning they have zero runtime overhead. They are incredibly useful for debugging, logging, and building assertion systems.

Available Constants

  • __LINE__

    Returns the current line number in the source file as an Int.

  • __FILE__

    Returns the name of the current file as a String.

  • __FUNC__

    Returns the name of the current function as a String. Returns an empty string if used outside a function.

  • __CLASS__

    Returns the name of the current class as a String. Returns "" if used outside a class.

Example: Custom Logger

Combine these constants to create a highly informative logging utility that tells you exactly where a message came from.

class Logger { static fun log(message: String, file: String, line: Int, className: String, funcName: String) { println("[${file}:${line}] ${className}::${funcName} -> ${message}") } } class NetworkManager { fun connect() { Logger.log("Attempting to connect...", __FILE__, __LINE__, __CLASS__, __FUNC__) } } val net = NetworkManager() net.connect() // Output: [index.atl:11] NetworkManager::NetworkManager.connect() -> Attempting to connect...

Example: Assertions

Magic constants perfectly pair with Autolang's built-in assert function to catch bugs early in development.

fun divide(a: Int, b: Int): Int { // If b is 0, this will throw an Exception showing the exact file and line! assert(b != 0, __FILE__, __LINE__) return a / b } println(divide(10, 0)) // Exception: index.al:3: Wrong