Language Basics
Data Types
BanglaCode is dynamically typed and supports several built-in data types including numbers, strings, booleans, arrays, maps, functions, and classes.
Type Overview
| Type | Description | Example | dhoron() Returns |
|---|
| Number (Integer) | Whole numbers | 42, -5 | "int" |
| Number (Float) | Decimal numbers | 3.14, -0.5 | "float" |
| String | Text | "hello" | "string" |
| Boolean | True/False | sotti, mittha | "boolean" |
| Null | No value | khali | "null" |
| Array | Ordered list | [1, 2, 3] | "array" |
| Map | Key-value pairs | {x: 1, y: 2} | "map" |
| Function | Callable | kaj(x) {} | "function" |
| Class | Blueprint | sreni X {} | "class" |
| Instance | Object instance | notun X() | "instance" |
Numbers
BanglaCode supports both integers and floating-point numbers:
| 1 | // Integers |
| 2 | dhoro age = 25; |
| 3 | dhoro negative = -10; |
| 4 | dhoro zero = 0; |
| 5 | |
| 6 | // Floating-point numbers |
| 7 | dhoro pi = 3.14159; |
| 8 | dhoro temperature = -5.5; |
| 9 | dhoro scientific = 1.5e2; // 150 |
| 10 | |
| 11 | // Arithmetic operations |
| 12 | dhoro sum = 10 + 5; // 15 |
| 13 | dhoro diff = 10 - 3; // 7 |
| 14 | dhoro product = 4 * 3; // 12 |
| 15 | dhoro quotient = 15 / 4; // 3.75 |
| 16 | dhoro remainder = 17 % 5; // 2 |
| 17 | dhoro power = 2 ** 10; // 1024 |
| 18 | |
| 19 | // Mixed integer and float |
| 20 | dhoro result = 5 + 3.5; // 8.5 |
Strings
Strings can be defined with double or single quotes:
| 1 | // String literals |
| 2 | dhoro greeting = "Namaskar"; |
| 3 | dhoro name = 'Rahim'; |
| 4 | |
| 5 | // String concatenation |
| 6 | dhoro fullName = "Rahim" + " " + "Khan"; |
| 7 | dekho(fullName); // "Rahim Khan" |
| 8 | |
| 9 | // String with numbers |
| 10 | dhoro message = "Age: " + lipi(25); |
| 11 | |
| 12 | // Multi-word strings |
| 13 | dhoro sentence = "This is a complete sentence."; |
| 14 | |
| 15 | // Empty string |
| 16 | dhoro empty = ""; |
| 17 | |
| 18 | // String length |
| 19 | dekho(dorghyo(greeting)); // 8 |
| 20 | |
| 21 | // Access character by index |
| 22 | dekho(greeting[0]); // "N" |
String Operations
| 1 | dhoro text = "Hello World"; |
| 2 | |
| 3 | // Length |
| 4 | dekho(dorghyo(text)); // 11 |
| 5 | |
| 6 | // Case conversion |
| 7 | dekho(boroHater(text)); // "HELLO WORLD" |
| 8 | dekho(chotoHater(text)); // "hello world" |
| 9 | |
| 10 | // Substring |
| 11 | dekho(angsho(text, 0, 5)); // "Hello" |
| 12 | dekho(angsho(text, 6)); // "World" |
| 13 | |
| 14 | // Find substring |
| 15 | dekho(khojo(text, "World")); // 6 |
| 16 | dekho(khojo(text, "xyz")); // -1 |
| 17 | |
| 18 | // Replace |
| 19 | dekho(bodlo(text, "World", "BanglaCode")); // "Hello BanglaCode" |
| 20 | |
| 21 | // Trim whitespace |
| 22 | dhoro padded = " hello "; |
| 23 | dekho(chhanto(padded)); // "hello" |
| 24 | |
| 25 | // Split string |
| 26 | dhoro csv = "a,b,c,d"; |
| 27 | dekho(bhag(csv, ",")); // ["a", "b", "c", "d"] |
Template Literals
Template literals use backticks (`) and allow embedded expressions with ${...} syntax:
| 1 | // Basic interpolation |
| 2 | dhoro name = "Rahim"; |
| 3 | dhoro greeting = `Hello ${name}!`; |
| 4 | dekho(greeting); // "Hello Rahim!" |
| 5 | |
| 6 | // Multiple expressions |
| 7 | dhoro age = 25; |
| 8 | dhoro city = "Dhaka"; |
| 9 | dhoro intro = `My name is ${name}, I'm ${age} years old, from ${city}`; |
| 10 | dekho(intro); // "My name is Rahim, I'm 25 years old, from Dhaka" |
| 11 | |
| 12 | // Arithmetic in expressions |
| 13 | dhoro num1 = 10; |
| 14 | dhoro num2 = 20; |
| 15 | dekho(`Sum: ${num1 + num2}`); // "Sum: 30" |
| 16 | dekho(`Product: ${num1 * num2}`); // "Product: 200" |
| 17 | |
| 18 | // Function calls in expressions |
| 19 | kaj square(x) { |
| 20 | ferao x * x; |
| 21 | } |
| 22 | dekho(`5 squared is ${square(5)}`); // "5 squared is 25" |
| 23 | |
| 24 | // Array and object access |
| 25 | dhoro colors = ["Red", "Green", "Blue"]; |
| 26 | dekho(`First color: ${colors[0]}`); // "First color: Red" |
| 27 | |
| 28 | dhoro person = {"naam": "Rahim", "age": 25}; |
| 29 | dekho(`Person: ${person["naam"]}`); // "Person: Rahim" |
| 30 | |
| 31 | // Conditional expressions |
| 32 | dhoro x = 10; |
| 33 | dekho(`Value is ${jodi (x > 5) { ferao "big"; } nahole { ferao "small"; }}`); |
| 34 | |
| 35 | // Chaining template literals |
| 36 | dhoro greeting1 = `Hello`; |
| 37 | dhoro greeting2 = `${greeting1} ${name}!`; |
| 38 | dekho(greeting2); // "Hello Rahim!" |
| 39 | |
| 40 | // Multiple interpolations |
| 41 | dekho(`${1} + ${2} = ${1 + 2}`); // "1 + 2 = 3" |
Booleans
Boolean values use Bengali keywords sotti (true) and mittha (false):
| 1 | // Boolean literals |
| 2 | dhoro isActive = sotti; // true |
| 3 | dhoro isComplete = mittha; // false |
| 4 | |
| 5 | // Boolean from comparison |
| 6 | dhoro isEqual = 5 == 5; // sotti |
| 7 | dhoro isGreater = 10 > 5; // sotti |
| 8 | dhoro isLess = 3 < 1; // mittha |
| 9 | |
| 10 | // Logical operations |
| 11 | dhoro andResult = sotti ebong mittha; // mittha (AND) |
| 12 | dhoro orResult = sotti ba mittha; // sotti (OR) |
| 13 | dhoro notResult = na sotti; // mittha (NOT) |
| 14 | |
| 15 | // Using ! for NOT |
| 16 | dhoro negated = !mittha; // sotti |
Null
The khali keyword represents the absence of a value:
| 1 | // Null value |
| 2 | dhoro empty = khali; |
| 3 | |
| 4 | // Check for null |
| 5 | jodi (empty == khali) { |
| 6 | dekho("Value is null"); |
| 7 | } |
| 8 | |
| 9 | // Functions without return value return null |
| 10 | kaj doSomething() { |
| 11 | dekho("Doing something"); |
| 12 | // No return statement |
| 13 | } |
| 14 | |
| 15 | dhoro result = doSomething(); |
| 16 | dekho(result == khali); // sotti |
Arrays
Arrays are ordered collections that can hold mixed types:
| 1 | // Array literals |
| 2 | dhoro numbers = [1, 2, 3, 4, 5]; |
| 3 | dhoro mixed = ["hello", 42, sotti, khali]; |
| 4 | dhoro nested = [[1, 2], [3, 4], [5, 6]]; |
| 5 | dhoro empty = []; |
| 6 | |
| 7 | // Access by index (0-based) |
| 8 | dekho(numbers[0]); // 1 |
| 9 | dekho(numbers[4]); // 5 |
| 10 | dekho(nested[1][0]); // 3 |
| 11 | |
| 12 | // Modify elements |
| 13 | numbers[0] = 100; |
| 14 | dekho(numbers); // [100, 2, 3, 4, 5] |
| 15 | |
| 16 | // Array length |
| 17 | dekho(dorghyo(numbers)); // 5 |
| 18 | |
| 19 | // Add element (push) |
| 20 | dhokao(numbers, 6); |
| 21 | dekho(numbers); // [100, 2, 3, 4, 5, 6] |
| 22 | |
| 23 | // Remove last element (pop) |
| 24 | dhoro last = berKoro(numbers); |
| 25 | dekho(last); // 6 |
| 26 | dekho(numbers); // [100, 2, 3, 4, 5] |
Array Operations
| 1 | dhoro arr = [3, 1, 4, 1, 5, 9, 2, 6]; |
| 2 | |
| 3 | // Slice |
| 4 | dekho(kato(arr, 2, 5)); // [4, 1, 5] |
| 5 | dekho(kato(arr, 5)); // [9, 2, 6] |
| 6 | |
| 7 | // Reverse |
| 8 | dekho(ulto(arr)); // [6, 2, 9, 5, 1, 4, 1, 3] |
| 9 | |
| 10 | // Check if element exists |
| 11 | dekho(ache(arr, 4)); // sotti |
| 12 | dekho(ache(arr, 10)); // mittha |
| 13 | |
| 14 | // Sort |
| 15 | dekho(saja([3, 1, 4, 1, 5])); // [1, 1, 3, 4, 5] |
| 16 | |
| 17 | // Join to string |
| 18 | dhoro words = ["hello", "world"]; |
| 19 | dekho(joro(words, " ")); // "hello world" |
Maps (Objects)
Maps are collections of key-value pairs:
| 1 | // Map literal |
| 2 | dhoro person = { |
| 3 | naam: "Rahim", |
| 4 | boyosh: 25, |
| 5 | city: "Dhaka", |
| 6 | active: sotti |
| 7 | }; |
| 8 | |
| 9 | // Access properties |
| 10 | dekho(person.naam); // "Rahim" |
| 11 | dekho(person["boyosh"]); // 25 |
| 12 | |
| 13 | // Modify properties |
| 14 | person.boyosh = 26; |
| 15 | person["city"] = "Kolkata"; |
| 16 | |
| 17 | // Add new properties |
| 18 | person.email = "rahim@example.com"; |
| 19 | |
| 20 | // Nested maps |
| 21 | dhoro company = { |
| 22 | name: "TechCorp", |
| 23 | address: { |
| 24 | street: "123 Main St", |
| 25 | city: "Dhaka" |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | dekho(company.address.city); // "Dhaka" |
| 30 | |
| 31 | // Get all keys |
| 32 | dekho(chabi(person)); // ["naam", "boyosh", "city", "active", "email"] |
Functions
Functions are first-class values in BanglaCode:
| 1 | // Named function |
| 2 | kaj add(a, b) { |
| 3 | ferao a + b; |
| 4 | } |
| 5 | |
| 6 | // Function expression (anonymous) |
| 7 | dhoro multiply = kaj(x, y) { |
| 8 | ferao x * y; |
| 9 | }; |
| 10 | |
| 11 | // Functions are values |
| 12 | dhoro operation = add; |
| 13 | dekho(operation(5, 3)); // 8 |
| 14 | |
| 15 | // Higher-order functions |
| 16 | kaj applyTwice(fn, x) { |
| 17 | ferao fn(fn(x)); |
| 18 | } |
| 19 | |
| 20 | kaj double(n) { |
| 21 | ferao n * 2; |
| 22 | } |
| 23 | |
| 24 | dekho(applyTwice(double, 5)); // 20 |
| 25 | |
| 26 | // Check type |
| 27 | dekho(dhoron(add)); // "function" |
Classes and Instances
Classes define blueprints for objects:
| 1 | // Class definition |
| 2 | sreni Car { |
| 3 | shuru(brand, model) { |
| 4 | ei.brand = brand; |
| 5 | ei.model = model; |
| 6 | } |
| 7 | |
| 8 | kaj getInfo() { |
| 9 | ferao ei.brand + " " + ei.model; |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | // Create instance |
| 14 | dhoro myCar = notun Car("Toyota", "Corolla"); |
| 15 | |
| 16 | // Check types |
| 17 | dekho(dhoron(Car)); // "class" |
| 18 | dekho(dhoron(myCar)); // "instance" |
| 19 | |
| 20 | // Access properties and methods |
| 21 | dekho(myCar.brand); // "Toyota" |
| 22 | dekho(myCar.getInfo()); // "Toyota Corolla" |
Type Conversion
| 1 | // To string |
| 2 | dekho(lipi(42)); // "42" |
| 3 | dekho(lipi(3.14)); // "3.14" |
| 4 | dekho(lipi(sotti)); // "true" |
| 5 | dekho(lipi([1, 2, 3])); // "[1, 2, 3]" |
| 6 | |
| 7 | // To number |
| 8 | dekho(sonkha("42")); // 42 |
| 9 | dekho(sonkha("3.14")); // 3.14 |
| 10 | dekho(sonkha("abc")); // Error or NaN |
| 11 | |
| 12 | // Type checking |
| 13 | dekho(dhoron(42)); // "int" |
| 14 | dekho(dhoron(3.14)); // "float" |
| 15 | dekho(dhoron("hi")); // "string" |