Mog is a new statically typed, compiled, embedded programming language designed to be written by LLMs and AI agents. It fits its full spec in 3200 tokens, compiles to native code via a safe Rust toolchain using the QBE backend, and uses a capability-based permission system so host applications control exactly what a Mog program can do. Key features include async/await, tensor support, no operator precedence, no implicit type coercion, and no uninitialized variables. It targets three agent use cases: one-off scripts, recurring hooks in the agent loop, and extending the agent itself. The compiler was built using the Volt coding agent over a three-week session. The language guide covers syntax basics including variables, types, operators, and control flow across multiple chapters.
Table of contents
OverviewExamplesWhy Mog?AlternativesThe LanguageThe Capability SystemThe CompilerCurrent StatusHello, WorldHow Mog Programs Are Compiled and RunProgram StructureCommentsPrint FunctionsA More Complete ExampleWhat Mog Is NotWhat’s NextCreating Bindings with :=Reassignment with =Type AnnotationsShadowingPractical ExamplesSummaryScalar TypesType ConversionsOperatorsFlat Operators (No Precedence)Common PatternsSummaryIf/ElseWhile LoopsFor LoopsBreak and ContinueMatchPractical ExamplesSummaryBasic Function DeclarationsVoid FunctionsParameters and Return TypesNamed Arguments and Default ValuesCalling ConventionsRecursionMath BuiltinsOther BuiltinsSummaryClosure SyntaxCapturing VariablesType Aliases for Function TypesPassing Closures to FunctionsReturning Closures from FunctionsClosures with Array MethodsSummaryString BasicsString InterpolationString ConcatenationString MethodsString SlicingString ComparisonConversionsPrint FunctionsBuilding StringsSummaryDeclaring StructsConstructing InstancesField AccessField MutationPassing Structs to FunctionsNo Methods — Use Standalone FunctionsConstructor FunctionsNested StructsStructs with Arrays and MapsPractical ExamplesSummaryArraysMapsSoA (Struct of Arrays)Putting It All TogetherSummaryResult<T>Optional ?TThe ? Propagation Operatortry-catch BlocksMatch Patterns for Result and OptionalPractical PatternsSummaryAsync FunctionsAwaitSpawnall() — Wait for Allrace() — Wait for FirstError Handling with AsyncSummaryPackage DeclarationPublic vs Private — The pub KeywordImporting PackagesMulti-Import SyntaxQualified AccessThe Module FileCircular Import DetectionPractical Example: Splitting a Program into PackagesSummaryThe Capability ModelDeclaring Capabilities: requires and optionalBuilt-in CapabilitiesPractical ExamplesConventional CapabilitiesCustom Host CapabilitiesSummaryThe Embedding LifecycleThe Embedding APIImplementing a Custom CapabilityMogValue: Data Exchange Between Host and ScriptResource Limits and TimeoutsSafety GuaranteesPractical Example: Embedding in a Game ServerSummaryPlugins — Dynamic Loading of Mog CodeHow Mog Compares to Other Embeddable LanguagesWhat Are Tensors?Creating TensorsTensor PropertiesElement AccessShape OperationsTensors and Host CapabilitiesPractical ExamplesSummaryType AliasesWith BlocksStruct-of-Arrays (SoA) PerformanceCompilation Backend: rqbeThe Interrupt SystemMemory ManagementWhat Mog Does NOT Have1. FizzBuzz2. Fibonacci Sequence3. Word Frequency Counter4. Simple Calculator with Error Handling5. Data Validation Chain6. Sorting and Filtering Pipeline7. Matrix Operations8. Agent Tool-Use Script9. Recursive Tree Traversal10. Async PipelineSummarySort: