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

TypeDescriptionExampledhoron() Returns
Number (Integer)Whole numbers42, -5"int"
Number (Float)Decimal numbers3.14, -0.5"float"
StringText"hello""string"
BooleanTrue/Falsesotti, mittha"boolean"
NullNo valuekhali"null"
ArrayOrdered list[1, 2, 3]"array"
MapKey-value pairs{x: 1, y: 2}"map"
FunctionCallablekaj(x) {}"function"
ClassBlueprintsreni X {}"class"
InstanceObject instancenotun X()"instance"

Numbers

BanglaCode supports both integers and floating-point numbers:

1// Integers
2dhoro age = 25;
3dhoro negative = -10;
4dhoro zero = 0;
5
6// Floating-point numbers
7dhoro pi = 3.14159;
8dhoro temperature = -5.5;
9dhoro scientific = 1.5e2; // 150
10
11// Arithmetic operations
12dhoro sum = 10 + 5; // 15
13dhoro diff = 10 - 3; // 7
14dhoro product = 4 * 3; // 12
15dhoro quotient = 15 / 4; // 3.75
16dhoro remainder = 17 % 5; // 2
17dhoro power = 2 ** 10; // 1024
18
19// Mixed integer and float
20dhoro result = 5 + 3.5; // 8.5

Strings

Strings can be defined with double or single quotes:

1// String literals
2dhoro greeting = "Namaskar";
3dhoro name = 'Rahim';
4
5// String concatenation
6dhoro fullName = "Rahim" + " " + "Khan";
7dekho(fullName); // "Rahim Khan"
8
9// String with numbers
10dhoro message = "Age: " + lipi(25);
11
12// Multi-word strings
13dhoro sentence = "This is a complete sentence.";
14
15// Empty string
16dhoro empty = "";
17
18// String length
19dekho(dorghyo(greeting)); // 8
20
21// Access character by index
22dekho(greeting[0]); // "N"

String Operations

1dhoro text = "Hello World";
2
3// Length
4dekho(dorghyo(text)); // 11
5
6// Case conversion
7dekho(boroHater(text)); // "HELLO WORLD"
8dekho(chotoHater(text)); // "hello world"
9
10// Substring
11dekho(angsho(text, 0, 5)); // "Hello"
12dekho(angsho(text, 6)); // "World"
13
14// Find substring
15dekho(khojo(text, "World")); // 6
16dekho(khojo(text, "xyz")); // -1
17
18// Replace
19dekho(bodlo(text, "World", "BanglaCode")); // "Hello BanglaCode"
20
21// Trim whitespace
22dhoro padded = " hello ";
23dekho(chhanto(padded)); // "hello"
24
25// Split string
26dhoro csv = "a,b,c,d";
27dekho(bhag(csv, ",")); // ["a", "b", "c", "d"]

Template Literals

Template literals use backticks (`) and allow embedded expressions with ${...} syntax:

1// Basic interpolation
2dhoro name = "Rahim";
3dhoro greeting = `Hello ${name}!`;
4dekho(greeting); // "Hello Rahim!"
5
6// Multiple expressions
7dhoro age = 25;
8dhoro city = "Dhaka";
9dhoro intro = `My name is ${name}, I'm ${age} years old, from ${city}`;
10dekho(intro); // "My name is Rahim, I'm 25 years old, from Dhaka"
11
12// Arithmetic in expressions
13dhoro num1 = 10;
14dhoro num2 = 20;
15dekho(`Sum: ${num1 + num2}`); // "Sum: 30"
16dekho(`Product: ${num1 * num2}`); // "Product: 200"
17
18// Function calls in expressions
19kaj square(x) {
20 ferao x * x;
21}
22dekho(`5 squared is ${square(5)}`); // "5 squared is 25"
23
24// Array and object access
25dhoro colors = ["Red", "Green", "Blue"];
26dekho(`First color: ${colors[0]}`); // "First color: Red"
27
28dhoro person = {"naam": "Rahim", "age": 25};
29dekho(`Person: ${person["naam"]}`); // "Person: Rahim"
30
31// Conditional expressions
32dhoro x = 10;
33dekho(`Value is ${jodi (x > 5) { ferao "big"; } nahole { ferao "small"; }}`);
34
35// Chaining template literals
36dhoro greeting1 = `Hello`;
37dhoro greeting2 = `${greeting1} ${name}!`;
38dekho(greeting2); // "Hello Rahim!"
39
40// Multiple interpolations
41dekho(`${1} + ${2} = ${1 + 2}`); // "1 + 2 = 3"

Booleans

Boolean values use Bengali keywords sotti (true) and mittha (false):

1// Boolean literals
2dhoro isActive = sotti; // true
3dhoro isComplete = mittha; // false
4
5// Boolean from comparison
6dhoro isEqual = 5 == 5; // sotti
7dhoro isGreater = 10 > 5; // sotti
8dhoro isLess = 3 < 1; // mittha
9
10// Logical operations
11dhoro andResult = sotti ebong mittha; // mittha (AND)
12dhoro orResult = sotti ba mittha; // sotti (OR)
13dhoro notResult = na sotti; // mittha (NOT)
14
15// Using ! for NOT
16dhoro negated = !mittha; // sotti

Null

The khali keyword represents the absence of a value:

1// Null value
2dhoro empty = khali;
3
4// Check for null
5jodi (empty == khali) {
6 dekho("Value is null");
7}
8
9// Functions without return value return null
10kaj doSomething() {
11 dekho("Doing something");
12 // No return statement
13}
14
15dhoro result = doSomething();
16dekho(result == khali); // sotti

Arrays

Arrays are ordered collections that can hold mixed types:

1// Array literals
2dhoro numbers = [1, 2, 3, 4, 5];
3dhoro mixed = ["hello", 42, sotti, khali];
4dhoro nested = [[1, 2], [3, 4], [5, 6]];
5dhoro empty = [];
6
7// Access by index (0-based)
8dekho(numbers[0]); // 1
9dekho(numbers[4]); // 5
10dekho(nested[1][0]); // 3
11
12// Modify elements
13numbers[0] = 100;
14dekho(numbers); // [100, 2, 3, 4, 5]
15
16// Array length
17dekho(dorghyo(numbers)); // 5
18
19// Add element (push)
20dhokao(numbers, 6);
21dekho(numbers); // [100, 2, 3, 4, 5, 6]
22
23// Remove last element (pop)
24dhoro last = berKoro(numbers);
25dekho(last); // 6
26dekho(numbers); // [100, 2, 3, 4, 5]

Array Operations

1dhoro arr = [3, 1, 4, 1, 5, 9, 2, 6];
2
3// Slice
4dekho(kato(arr, 2, 5)); // [4, 1, 5]
5dekho(kato(arr, 5)); // [9, 2, 6]
6
7// Reverse
8dekho(ulto(arr)); // [6, 2, 9, 5, 1, 4, 1, 3]
9
10// Check if element exists
11dekho(ache(arr, 4)); // sotti
12dekho(ache(arr, 10)); // mittha
13
14// Sort
15dekho(saja([3, 1, 4, 1, 5])); // [1, 1, 3, 4, 5]
16
17// Join to string
18dhoro words = ["hello", "world"];
19dekho(joro(words, " ")); // "hello world"

Maps (Objects)

Maps are collections of key-value pairs:

1// Map literal
2dhoro person = {
3 naam: "Rahim",
4 boyosh: 25,
5 city: "Dhaka",
6 active: sotti
7};
8
9// Access properties
10dekho(person.naam); // "Rahim"
11dekho(person["boyosh"]); // 25
12
13// Modify properties
14person.boyosh = 26;
15person["city"] = "Kolkata";
16
17// Add new properties
18person.email = "rahim@example.com";
19
20// Nested maps
21dhoro company = {
22 name: "TechCorp",
23 address: {
24 street: "123 Main St",
25 city: "Dhaka"
26 }
27};
28
29dekho(company.address.city); // "Dhaka"
30
31// Get all keys
32dekho(chabi(person)); // ["naam", "boyosh", "city", "active", "email"]

Functions

Functions are first-class values in BanglaCode:

1// Named function
2kaj add(a, b) {
3 ferao a + b;
4}
5
6// Function expression (anonymous)
7dhoro multiply = kaj(x, y) {
8 ferao x * y;
9};
10
11// Functions are values
12dhoro operation = add;
13dekho(operation(5, 3)); // 8
14
15// Higher-order functions
16kaj applyTwice(fn, x) {
17 ferao fn(fn(x));
18}
19
20kaj double(n) {
21 ferao n * 2;
22}
23
24dekho(applyTwice(double, 5)); // 20
25
26// Check type
27dekho(dhoron(add)); // "function"

Classes and Instances

Classes define blueprints for objects:

1// Class definition
2sreni 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
14dhoro myCar = notun Car("Toyota", "Corolla");
15
16// Check types
17dekho(dhoron(Car)); // "class"
18dekho(dhoron(myCar)); // "instance"
19
20// Access properties and methods
21dekho(myCar.brand); // "Toyota"
22dekho(myCar.getInfo()); // "Toyota Corolla"

Type Conversion

1// To string
2dekho(lipi(42)); // "42"
3dekho(lipi(3.14)); // "3.14"
4dekho(lipi(sotti)); // "true"
5dekho(lipi([1, 2, 3])); // "[1, 2, 3]"
6
7// To number
8dekho(sonkha("42")); // 42
9dekho(sonkha("3.14")); // 3.14
10dekho(sonkha("abc")); // Error or NaN
11
12// Type checking
13dekho(dhoron(42)); // "int"
14dekho(dhoron(3.14)); // "float"
15dekho(dhoron("hi")); // "string"