Every snippet below is a real, runnable .mantra file. Examples 12–14 use v0.2.0 packages. Run with
mantrac <file.mantra> or compile to native with mantrac --emit native <file.mantra>
Variables (let/mut), functions with type annotations, conditionals, while loops.
Class declaration, __init__, self, pub def, private fields with underscore convention.
Define a Shape interface; Circle and Rectangle implement it. Polymorphic dispatch via interface type.
Extend a base class with extends, call super().__init__(), and override parent methods.
Abstract class with abstract def forces subclasses to implement; shared default behaviour lives in the abstract class.
Class-level static constants and static def functions. Access without instantiation via ClassName.method().
Computed @property getters: convert Celsius to Fahrenheit and Kelvin without storing redundant fields.
Build a Car that owns an Engine. Pass objects as constructor arguments — composition over deep inheritance.
Container class with List as internal storage. push(), pop(), peek(), and is_empty() semantics.
Component → UIElement → Button. Each level calls super().describe() to build the description string.
Interface-driven database adapter, HTTP response model, and a main() wiring them together — the foundation of mantra.sql.orm and mantra.net.http.