Skip to content

Syntax Overview

Syntax Overview

Thagore uses Python-like syntax with indentation-based scoping. Every block is opened by a : and indented. Source files use the .tg extension.

Quick Reference

complete_example.tg
# Import a standard library module
import fs
# Define a struct
struct Point:
x: i32
y: i32
# Implement methods on the struct
impl Point:
func magnitude(self) -> i32:
return self.x * self.x + self.y * self.y
# Define a function
func greet(name: String) -> String:
return "Hello, " + name + "!"
# Entry point
func main() -> i32:
let p = Point(3, 4)
let mag = p.magnitude()
print(mag)
let msg = greet("Developer")
print(msg)
let i = 0
while (i < 5):
print(i)
i = i + 1
return 0

Syntax Topics

Print & Output

The print() function, outputting values, and side effects.

Variables & let

Variable declarations with let, type inference, reassignment, and scope rules.

Functions

Function declarations, parameters, return types, and the main entry point.

Control Flow

if/else, while loops, for..in range loops, and match expressions.

Structs & impl

Struct definitions, method implementations, and operator overloading.

FFI & Import

Module imports, extern func for C FFI, and the module system.

Advanced Features

Enums, match, traits, comptime, defer, unsafe, and closures.

Minimal Program

The simplest valid Thagore program:

minimal.tg
print("Hello!")

Thagore supports top-level statements — if your source has no func main(), the compiler wraps top-level code in an auto-generated main function.

Program with Explicit Entry Point

explicit_main.tg
func main() -> i32:
print("Hello from main!")
return 0