🚀 Mitra Codiga Documentation
← Back to EditorOverview
Mitra Codiga is a modern, expressive programming language interpreter built with Python. It combines the simplicity of scripting languages with powerful features like first-class functions, modules, and robust error handling.
Key Features
✨ Variables & Types
Numbers, strings, booleans, lists, dictionaries, and more.
🔄 Control Flow
if/elif/else, while, for-in loops with break/continue.
⚡ Functions
Named functions, lambdas, recursion, and closures.
📦 Modules
Import and use code from other files.
🛡️ Error Handling
Try-catch blocks for graceful error management.
🔧 Standard Library
JSON, file I/O, time utilities, and more.
Quick Start
Online (Web UI)
You're already here! Just start typing code in the editor and click "Run Code" or press Ctrl+Enter.
Local REPL
python mc_lang.py
Then type code directly and press Enter to execute.
Run a File
python mc_lang.py myprogram.mc
Start Web Server
python web_app.py
Then open http://localhost:5000 in your browser.
Syntax & Basics
Variables
Declare variables with let:
let name = "Alice"
let age = 30
let active = true
let nothing = null
Comments
# This is a comment
let x = 10 # inline comment too
Statements
Statements are separated by newlines or semicolons:
let x = 5
let y = 10
print(x + y)
# Or on one line:
let x = 5; let y = 10; print(x + y)
Blocks
Use curly braces for blocks:
if x > 5 {
print("big")
}
Data Types
Numbers
let a = 42 # Integer
let b = 3.14 # Float
let c = 2 ** 8 # Power: 256
Strings
let s = "Hello, World!"
let empty = ""
let escaped = "Line 1\nLine 2\t\tTabbed"
Booleans & Null
let t = true
let f = false
let n = null
Lists
let nums = [1, 2, 3, 4, 5]
let mixed = [1, "two", true, null]
let nested = [[1, 2], [3, 4]]
print(nums[0]) # 1
nums[1] = 20 # Mutation
Dictionaries
Three ways to create a dictionary:
# Shorthand literal
let user = { name: "Alice", age: 30 }
# Keyword literal
let config = dict { theme: "dark", version: 1 }
# Constructor
let meta = dict(author="Sarthak", year=2025)
# Access and mutate
print(user["name"]) # "Alice"
user["city"] = "Paris"
print(user.keys()) # ["name", "age", "city"]
Control Flow
If/Elif/Else
if x > 10 {
print("big")
} elif x > 5 {
print("medium")
} else {
print("small")
}
While Loops
let i = 0
while i < 5 {
print(i)
i = i + 1
}
For-In Loops
for x in [1, 2, 3] {
print(x)
}
for i in range(5) {
print(i)
}
Break & Continue
for i in range(10) {
if i == 2 { continue } # Skip
if i == 6 { break } # Exit
print(i) # 0, 1, 3, 4, 5
}
Functions & Lambdas
Named Functions
fun add(a, b) {
return a + b
}
print(add(3, 7)) # 10
Recursion
fun factorial(n) {
if n <= 1 { return 1 }
return n * factorial(n - 1)
}
print(factorial(5)) # 120
Lambda (Anonymous Functions)
let square = lambda x: x * x
print(square(5)) # 25
let add = lambda a, b: a + b
print(add(3, 4)) # 7
Lambda with Complex Expressions
let filter_evens = lambda x: (x % 2 == 0) and (x > 2)
let result = filter(filter_evens, [1, 2, 3, 4, 5])
print(result) # [4]
Built-in Functions
I/O
| Function | Description | Example |
|---|---|---|
print(...) |
Print to output | print("hello", 42) |
input(prompt) |
Read from input | let name = input("Name: ") |
Type Conversion
| Function | Description | Example |
|---|---|---|
int(x) |
Convert to integer | int("42") |
float(x) |
Convert to float | float("3.14") |
str(x) |
Convert to string | str(42) |
type(x) |
Get type name | type([1,2]) |
Collection Functions
| Function | Description | Example |
|---|---|---|
len(x) |
Length of collection | len([1,2,3]) |
range(n) |
Range 0 to n-1 | range(5) |
map(fn, list) |
Apply fn to each element | map(lambda x: x*2, [1,2,3]) |
filter(fn, list) |
Keep elements where fn is true | filter(lambda x: x>2, [1,2,3]) |
sum(list) |
Sum all elements | sum([1,2,3]) |
min(list) |
Minimum element | min([3,1,2]) |
max(list) |
Maximum element | max([3,1,2]) |
sorted(list) |
Sort a list | sorted([3,1,2]) |
reversed(list) |
Reverse a list | reversed([1,2,3]) |
enumerate(list) |
Get (index, value) pairs | enumerate(["a","b"]) |
zip(a, b) |
Combine lists element-wise | zip([1,2], ["a","b"]) |
all(list) |
True if all elements are truthy | all([true, 1, "a"]) |
any(list) |
True if any element is truthy | any([false, 0, "a"]) |
Math Functions
| Function | Description | Example |
|---|---|---|
abs(x) |
Absolute value | abs(-5) |
round(x, n) |
Round to n decimal places | round(3.14159, 2) |
Standard Library
JSON
let obj = json_parse("{\"a\":1,\"b\":[1,2,3]}")
print(obj["a"]) # 1
let json_str = json_stringify(dict(x=10, y=20))
print(json_str) # {"x": 10, "y": 20}
Time & Date
let current = now()
print(current) # 2025-12-06T14:30:45
let epoch = timestamp()
print(epoch) # 1733504445
sleep(1) # Sleep for 1 second
File I/O (CLI only)
write_file("data.txt", "Hello")
append_file("data.txt", " World")
let content = read_file("data.txt")
print(content) # Hello World
Modules
# Create math_utils.mc:
# fun add(a, b) { return a + b }
# In your code:
let math = import "math_utils.mc"
print(math["add"](2, 3)) # 5
Examples
FizzBuzz
for i in range(1, 16) {
if i % 15 == 0 {
print("FizzBuzz")
} elif i % 3 == 0 {
print("Fizz")
} elif i % 5 == 0 {
print("Buzz")
} else {
print(i)
}
}
List Processing
let nums = [1, 2, 3, 4, 5]
let squared = map(lambda x: x * x, nums)
let evens = filter(lambda x: x % 2 == 0, squared)
print(sum(evens)) # 4 + 16 = 20
Data Structure
let users = [
{ name: "Alice", age: 30 },
{ name: "Bob", age: 25 },
{ name: "Charlie", age: 35 }
]
for user in users {
print(user["name"], "is", user["age"])
}
Error Handling
Try-Catch
try {
let x = 10 / 0
} catch (err) {
print("Error caught:", err)
}
Error Messages
The error variable in the catch block contains the error message as a string. Common errors:
division by zero— from dividing by 0Undefined name 'x'— variable not declaredIndex error— accessing out-of-bounds indexModule not found— import file doesn't exist
Web Error UI
In the web editor, parse errors show an error pane above the code with the exact line and column. The cursor jumps to the error location.
Tips & Tricks
Auto-Indentation
Press Enter to auto-indent. Lines ending with { or : add extra indentation.
Auto-Bracket Closing
Type (, [, {, or " and the closing character appears automatically.
Keyboard Shortcuts
Ctrl+Enter— Run codeTab— Insert 4 spaces for indentation
Variable Naming
Use snake_case for variables and functions:
let user_name = "Alice"
fun get_full_name(first, last) { return first + " " + last }
String Escape Sequences
| Sequence | Meaning |
|---|---|
\n |
Newline |
\t |
Tab |
\\ |
Backslash |
\" |
Double quote |
Operator Precedence
**(power)*/%(multiply, divide, modulo)+-(add, subtract)==!=<<=>>=(comparisons)not(logical NOT)and(logical AND)or(logical OR)
Truthiness
In boolean contexts, these are falsy:
falsenull0and0.0""(empty string)[](empty list){}(empty dict)
Everything else is truthy.