Back Original

Show HN: The Mog Programming Language

Contents Back to top
  1. Mog: A Programming Language for AI Agents
  2. Overview
  3. Examples
  4. Agent hook
  5. Async HTTP with retry
  6. FFT on tensors
  7. Why Mog?
  8. Alternatives
  9. The Language
  10. Example
  11. The Capability System
  12. The Compiler
  13. Current Status
  14. The Mog Language Guide
  15. Chapter 1: Your First Mog Program
  16. Hello, World
  17. How Mog Programs Are Compiled and Run
  18. Program Structure
  19. Comments
  20. Print Functions
  21. A More Complete Example
  22. What Mog Is Not
  23. What's Next
  24. Chapter 2: Variables and Bindings
  25. Creating Bindings with `:=`
  26. Reassignment with `=`
  27. Type Annotations
  28. Shadowing
  29. Practical Examples
  30. Swapping Two Values
  31. Fibonacci Sequence
  32. Processing a List
  33. Counting Occurrences
  34. Summary
  35. Chapter 3: Types and Operators
  36. Scalar Types
  37. Integers
  38. Explicit-Width Integers
  39. Floats
  40. Booleans
  41. Strings
  42. Type Conversions
  43. The `as` Keyword
  44. String Conversions
  45. No Implicit Conversions
  46. Operators
  47. Arithmetic Operators
  48. Comparison Operators
  49. Logical Operators
  50. Bitwise Operators
  51. String Concatenation
  52. Flat Operators (No Precedence)
  53. Why no precedence?
  54. Common Patterns
  55. Clamping a Value
  56. Safe Division
  57. Type-Aware Accumulation
  58. Bitflag Permissions
  59. Building Results with Type Conversion
  60. Summary
  61. Chapter 4: Control Flow
  62. If/Else
  63. Nested Conditions
  64. If as Expression
  65. While Loops
  66. Accumulator Pattern
  67. Convergence Loops
  68. Infinite Loops
  69. For Loops
  70. For-To (Inclusive Range)
  71. For-In Range (Exclusive End)
  72. When to Use Which
  73. For-In Array
  74. For-In with Index
  75. For-In Map
  76. Break and Continue
  77. Break
  78. Continue
  79. Combined Break and Continue
  80. Break and Continue in Nested Loops
  81. Match
  82. Matching Integers
  83. Matching Strings
  84. Multi-Statement Arms
  85. Match as Expression
  86. Matching on Result and Optional
  87. Practical Examples
  88. Fibonacci (Iterative)
  89. Sum of Squares
  90. Linear Search
  91. Bubble Sort
  92. FizzBuzz
  93. GCD (Euclidean Algorithm)
  94. Prime Checker
  95. Command Dispatcher with Match
  96. Summary
  97. Chapter 5: Functions
  98. Basic Function Declarations
  99. Void Functions
  100. Parameters and Return Types
  101. Named Arguments and Default Values
  102. Calling Conventions
  103. Recursion
  104. Math Builtins
  105. Other Builtins
  106. Output Functions
  107. Conversion Functions
  108. A Complete Example
  109. Summary
  110. Chapter 6: Closures and Higher-Order Functions
  111. Closure Syntax
  112. Capturing Variables
  113. Value Capture Semantics
  114. Type Aliases for Function Types
  115. Passing Closures to Functions
  116. Returning Closures from Functions
  117. Closures with Array Methods
  118. filter
  119. map
  120. sort
  121. Chaining Methods
  122. Summary
  123. Chapter 7: Strings
  124. String Basics
  125. Escape Sequences
  126. Immutability
  127. UTF-8 Encoding
  128. String Interpolation
  129. String Concatenation
  130. String Methods
  131. `.len`
  132. `.contains(substr)`
  133. `.starts_with(prefix)` and `.ends_with(suffix)`
  134. `.upper()` and `.lower()`
  135. `.trim()`
  136. `.replace(old, new)`
  137. `.split(delimiter)`
  138. `.index_of(substr)`
  139. Method Chaining
  140. String Slicing
  141. String Comparison
  142. Conversions
  143. To String: `str()`
  144. From String: Parsing
  145. Print Functions
  146. Generic Printing
  147. Type-Specific Variants
  148. Building Strings
  149. Concatenation in Loops
  150. Formatting Tables
  151. Building Messages
  152. Parsing with Validation
  153. Summary
  154. Chapter 8: Structs
  155. Declaring Structs
  156. Constructing Instances
  157. Field Access
  158. Field Mutation
  159. Passing Structs to Functions
  160. No Methods — Use Standalone Functions
  161. Constructor Functions
  162. Nested Structs
  163. Structs with Arrays and Maps
  164. Practical Examples
  165. RGB Color Manipulation
  166. Tree Structure
  167. Summary
  168. Chapter 9: Collections
  169. Arrays
  170. Array Literals
  171. Repeat Syntax
  172. Type Annotations
  173. Indexing
  174. Iteration
  175. `.push()` and `.pop()`
  176. `.slice()`
  177. `.contains()`
  178. `.reverse()`
  179. `.join()`
  180. `.filter()`
  181. `.map()`
  182. `.sort()`
  183. Chaining Array Methods
  184. Maps
  185. Creating Maps
  186. Access and Mutation
  187. `.has()` — Checking Key Existence
  188. `.len()`, `.keys()`, `.values()`
  189. `.delete()` — Removing Entries
  190. Iterating Maps
  191. Practical Example: Word Counting
  192. Practical Example: Grouping Data
  193. SoA (Struct of Arrays)
  194. When to Use SoA
  195. Construction
  196. Field Access
  197. Iteration Patterns
  198. Practical Example: Particle Simulation
  199. Practical Example: Column Operations
  200. Putting It All Together
  201. Data Processing Pipeline
  202. Filter-Map-Sort Pipeline
  203. Summary
  204. Chapter 10: Error Handling
  205. Result\<T\>
  206. Optional ?T
  207. The ? Propagation Operator
  208. try-catch Blocks
  209. Match Patterns for Result and Optional
  210. Practical Patterns
  211. Validation Chains
  212. Safe Parsing
  213. Converting Between Result and Optional
  214. Providing Defaults for Optionals
  215. Error Message Formatting
  216. Collecting Results
  217. Nested Results
  218. Summary
  219. Chapter 11: Async Programming
  220. Async Functions
  221. Await
  222. Spawn
  223. all() — Wait for All
  224. race() — Wait for First
  225. Error Handling with Async
  226. Retry Pattern
  227. Fan-out / Fan-in
  228. Summary
  229. Chapter 12: Modules and Packages
  230. Package Declaration
  231. Public vs Private — The `pub` Keyword
  232. Importing Packages
  233. Multi-Import Syntax
  234. Qualified Access
  235. The Module File
  236. Circular Import Detection
  237. Practical Example: Splitting a Program into Packages
  238. Summary
  239. Chapter 13: Capabilities — Safe I/O
  240. The Capability Model
  241. Declaring Capabilities: `requires` and `optional`
  242. Built-in Capabilities
  243. `fs` — File System
  244. `process` — Process and Environment
  245. Practical Examples
  246. Copying a File
  247. Reading Configuration
  248. Timed Operations
  249. Simple Logger Using `fs`
  250. Conventional Capabilities
  251. Custom Host Capabilities
  252. `.mogdecl` Files
  253. Using a Custom Capability
  254. How the Pieces Fit Together
  255. Capability Validation Example
  256. Summary
  257. Chapter 14: Embedding Mog in a Host Application
  258. The Embedding Lifecycle
  259. The Embedding API
  260. VM Lifecycle
  261. Registering Capabilities
  262. Validating Script Requirements
  263. Implementing a Custom Capability
  264. Step 1: Write the `.mogdecl` File
  265. Step 2: Implement the Host Functions
  266. Step 3: Build the Registration Table and Register
  267. Step 4: Use It from Mog
  268. MogValue: Data Exchange Between Host and Script
  269. Constructing Values
  270. Extracting Arguments
  271. Returning Errors
  272. Opaque Handles
  273. Resource Limits and Timeouts
  274. Memory Limits
  275. CPU Time Limits
  276. Manual Timeout Arming
  277. Host-Initiated Interrupts
  278. Stack Overflow Protection
  279. Complete Timeout Example
  280. Safety Guarantees
  281. Practical Example: Embedding in a Game Server
  282. The `.mogdecl` File
  283. The Host Implementation (C)
  284. The Player Script (Mog)
  285. The Host Runner
  286. Summary
  287. Plugins — Dynamic Loading of Mog Code
  288. Plugin Overview
  289. Writing a Plugin
  290. Compiling a Plugin
  291. Loading and Calling Plugins
  292. Plugin C API Reference
  293. Capability Sandboxing
  294. Plugin Protocol (Advanced)
  295. How Mog Compares to Other Embeddable Languages
  296. Chapter 15: Tensors — N-Dimensional Arrays
  297. What Are Tensors?
  298. Creating Tensors
  299. From a Literal
  300. Static Constructors
  301. Supported Dtypes
  302. Tensor Properties
  303. Element Access
  304. Reading Elements
  305. Writing Elements
  306. Computing Flat Indices
  307. Shape Operations
  308. Reshape
  309. Transpose
  310. Tensors and Host Capabilities
  311. Passing Tensors to Host Functions
  312. Composing Operations
  313. Why This Design?
  314. Practical Examples
  315. Creating a Data Batch
  316. Reading Model Output Elements
  317. Preparing Input Tensors
  318. End-to-End Inference Script
  319. Summary
  320. Chapter 16: Advanced Topics
  321. Type Aliases
  322. With Blocks
  323. Struct-of-Arrays (SoA) Performance
  324. Compilation Backend: rqbe
  325. The Interrupt System
  326. Memory Management
  327. What Mog Does NOT Have
  328. Chapter 17: Cookbook — Practical Programs
  329. 1. FizzBuzz
  330. 2. Fibonacci Sequence
  331. Recursive
  332. Iterative
  333. 3. Word Frequency Counter
  334. 4. Simple Calculator with Error Handling
  335. 5. Data Validation Chain
  336. 6. Sorting and Filtering Pipeline
  337. 7. Matrix Operations
  338. 8. Agent Tool-Use Script
  339. 9. Recursive Tree Traversal
  340. 10. Async Pipeline
  341. Summary