Example Programs
20 ready-to-run programs covering everything from basics to advanced features. Each file is in the examples/ directory.
rampyaaryan examples/01_namaste_duniya.ram
All Examples
- Namaste Duniya — Hello World
- Variables — Data types & variables
- Conditions — If/else logic
- Loops — While & for loops
- Functions — Functions & recursion
- Lists — Dynamic arrays
- Calculator — Interactive calculator
- Sorting — Sorting algorithms
- Number Game — Guessing game
- Patterns — Star patterns & art
- String Magic — String operations
- Math & Science — Math functions
- File I/O — Reading & writing files
- Advanced Lists — Higher-order ops
- Type System — Type checking & conversion
- Shabdkosh — Maps & dictionaries
- Bitwise — Bitwise operations
- Higher-Order — Map, filter, reduce
- Mini Database — CRUD with maps
- Feature Showcase — Everything combined
01 — Namaste Duniya
The classic first program. Every journey starts here.
examples/01_namaste_duniya.ram
likho "Namaste Duniya!"
likho "Rampyaaryan mein aapka swagat hai!"
likho ""
likho "Yeh pehla program hai - bahut simple!"
02 — Variables
Learn about all 7 data types and variable declarations.
examples/02_variables.ram
maano naam = "Aryan"
maano umar = 21
maano pi = 3.14159
maano active = sach
maano kuch = khali
maano fruits = ["seb", "kela", "aam"]
likho "Naam:", naam
likho "Umar:", umar
likho "Type:", prakar(naam)
03 — Conditions
Conditional logic with agar, warna agar, and warna.
examples/03_conditions.ram
maano umar = 18
agar umar >= 18 {
likho "Vote de sakte ho!"
} warna agar umar >= 13 {
likho "Teenager ho!"
} warna {
likho "Bachche ho!"
}
04 — Loops
While loops (jab tak) and for loops (har) with break/continue.
examples/04_loops.ram
# Countdown
maano i = 5
jab tak i > 0 {
likho i
i = i - 1
}
likho "LAUNCH!"
# Multiplication table
har i = 1; i <= 10; i = i + 1 {
likho format("7 x {} = {}", i, 7 * i)
}
05 — Functions
Functions, recursion, closures, and first-class functions.
examples/05_functions.ram
kaam factorial(n) {
agar n <= 1 { wapas do 1 }
wapas do n * factorial(n - 1)
}
likho factorial(10) # 3628800
# Closure example
kaam counter() {
maano count = 0
kaam increment() {
count = count + 1
wapas do count
}
wapas do increment
}
maano c = counter()
likho c(), c(), c() # 1 2 3
06 — Lists
Dynamic arrays with sorting, slicing, and statistics.
examples/06_lists.ram
maano nums = [42, 17, 89, 3, 56]
joodo(nums, 100) # Append
kram(nums) # Sort
likho "Sorted:", nums
likho "Sum:", jod(nums)
likho "Avg:", ausat(nums)
likho "Max:", sabse_bada(nums)
likho "Min:", sabse_chhota(nums)
07 — Calculator
Interactive calculator with a Hinglish menu UI supporting 7 operations.
examples/07_calculator.ram
kaam calculator() {
likho "1. Jodo (+) 2. Ghataao (-)"
likho "3. Guna (*) 4. Bhaag (/)"
likho "5. Power 6. Modulo"
maano n = sankhya(pucho("Choose: "))
maano a = sankhya(pucho("Pehla number: "))
maano b = sankhya(pucho("Doosra number: "))
agar n == 1 { likho a + b }
warna agar n == 2 { likho a - b }
warna agar n == 3 { likho a * b }
warna agar n == 4 { likho a / b }
}
calculator()
08 — Sorting
Bubble sort and selection sort implemented in Rampyaaryan.
examples/08_sorting.ram
kaam bubble_sort(arr) {
maano n = lambai(arr)
har i = 0; i < n; i = i + 1 {
har j = 0; j < n - i - 1; j = j + 1 {
agar arr[j] > arr[j + 1] {
maano temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp
}
}
}
wapas do arr
}
maano data = [64, 34, 25, 12, 22, 11, 90]
likho "Sorted:", bubble_sort(data)
09 — Number Guessing Game
Guess the random number in 7 attempts with hints.
examples/09_number_game.ram
maano secret = yaadrchik(1, 100)
maano attempts = 0
maano guessed = jhooth
jab tak attempts < 7 aur nahi guessed {
attempts = attempts + 1
maano guess = sankhya(pucho("Guess: "))
agar guess == secret {
likho "SAHI JAWAB!", attempts, "mein!"
guessed = sach
} warna agar guess < secret {
likho "Bada number try karo"
} warna {
likho "Chhota number try karo"
}
}
10 — Patterns
Star patterns and ASCII art using nested loops.
examples/10_patterns.ram
# Right triangle
har i = 1; i <= 5; i = i + 1 {
likho dohrao("* ", i)
}
# Diamond
har i = 1; i <= 5; i = i + 1 {
likho dohrao(" ", 5 - i) + dohrao("* ", i)
}
11 — String Magic
All 27 string functions demonstrated with real examples.
examples/11_string_magic.ram
maano s = "Rampyaaryan Language"
likho bade_akshar(s) # RAMPYAARYAN LANGUAGE
likho title_case("hello world") # Hello World
likho badlo(s, "Language", "Bhasha")
likho center("STAR", 20, "=") # ========STAR========
likho pad_left("42", 8, "0") # 00000042
likho kya_ank("12345") # sach
12 — Math & Science
Trigonometry, logarithms, primes, Fibonacci, and more.
examples/12_math_science.ram
likho "PI =", PI()
likho "E =", E()
likho "sqrt(144) =", sqrt_val(144)
likho "10! =", factorial(10)
likho "fib(20) =", fib(20)
likho "Is 97 prime?", kya_prime(97)
likho "GCD(48,18) =", gcd(48, 18)
likho "sin(PI/2) =", sin_val(PI() / 2)
13 — File I/O
Read, write, and append files. Check if files exist.
examples/13_file_io.ram
# Write a file
likho_file("output.txt", "Hello World!\n")
joodo_file("output.txt", "Line 2\n")
# Read it back
maano data = padho_file("output.txt")
likho data
# Check existence
agar file_hai("output.txt") {
likho "File found!"
}
14 — Advanced Lists
Flatten, chunk, rotate, copy, and more list operations.
examples/14_advanced_lists.ram
likho flatten([[1,2],[3,[4,5]]]) # [1,2,3,4,5]
likho tukda([1,2,3,4,5], 2) # [[1,2],[3,4],[5]]
likho ghuma([1,2,3,4,5], 2) # [3,4,5,1,2]
maano a = [1,2,3]
maano b = copy_suchi(a)
joodo(b, 4)
likho "a:", a # [1,2,3] (unchanged)
likho "b:", b # [1,2,3,4]
15 — Type System
Type checking, type conversion, and runtime introspection.
examples/15_type_system.ram
likho prakar(42) # sankhya
likho prakar("hello") # shabd
likho kya_purn(42) # sach
likho kya_purn(3.14) # jhooth
likho sankhya("42") # 42
likho shabd(3.14) # "3.14"
likho purn(3.99) # 3
likho bool_val(0) # jhooth
16 — Shabdkosh (Maps)
Dictionaries with literal syntax and all 9 map functions.
examples/16_shabdkosh.ram
maano student = {"naam": "Aryan", "umar": 20}
likho student["naam"]
student["grade"] = "A"
likho chabi(student) # keys
likho mulya(student) # values
likho map_lambai(student) # 3
likho map_hai(student, "naam") # sach
17 — Bitwise Operations
AND, OR, XOR, NOT, shifts, and base conversions.
examples/17_bitwise.ram
maano a = 12 # 1100
maano b = 10 # 1010
likho "AND:", a & b # 8
likho "OR:", a | b # 14
likho "XOR:", a ^ b # 6
likho "NOT:", ~a # -13
likho "Hex:", hex_shabd(255) # ff
likho "Bin:", bin_shabd(255) # 11111111
18 — Higher-Order Functions
Map, filter, reduce, zip, enumerate, and more.
examples/18_higher_order.ram
kaam square(x) { wapas do x * x }
kaam is_even(x) { wapas do x % 2 == 0 }
kaam add(a, b) { wapas do a + b }
maano nums = [1, 2, 3, 4, 5]
likho naksha(nums, square) # [1,4,9,16,25]
likho chhaano(nums, is_even) # [2,4]
likho ikkatha(nums, add, 0) # 15
likho jodi_banao([1,2], ["a","b"]) # [[1,"a"],[2,"b"]]
19 — Mini Database
CRUD operations using maps as records — add, search, delete, list.
examples/19_mini_database.ram
maano db = []
kaam add_record(naam, umar) {
maano record = {"naam": naam, "umar": umar}
joodo(db, record)
likho "Added:", naam
}
kaam find_record(naam) {
har i = 0; i < lambai(db); i = i + 1 {
agar db[i]["naam"] == naam {
wapas do db[i]
}
}
wapas do khali
}
add_record("Aryan", 20)
add_record("Priya", 22)
likho find_record("Aryan")
20 — Feature Showcase
A comprehensive demo that exercises every major language feature in one program.
examples/20_feature_showcase.ram
# Tests all data types
kaam test_types() {
maano num = 42
maano str = "Namaste"
maano lst = [1, 2, 3]
maano mp = {"key": "value"}
likho typeof_val(num), typeof_val(str)
likho typeof_val(lst), typeof_val(mp)
}
test_types()
# Math showcase
likho "factorial(10):", factorial(10)
likho "fib(15):", fib(15)
likho "kya_prime(97):", kya_prime(97)
examples/ directory of the repository. Clone the repo and run them with rampyaaryan <filename>.ram.