Reference

Built-in Functions Reference

BanglaCode provides 135+ built-in functions for I/O, type conversion, string manipulation, array operations, math, file handling, HTTP, JSON, environment variables, networking (TCP/UDP/WebSocket), database connectivity (PostgreSQL/MySQL/MongoDB/Redis), and complete OS-level system access.

Input/Output

FunctionParametersReturnsDescription
dekhoargs...khaliPrint values to console
nao[prompt]stringRead user input from console
1// Print output
2dekho("Hello");
3dekho("Name:", "Rahim", "Age:", 25);
4
5// Read input
6dhoro naam = nao("Enter your name: ");
7dekho("Hello,", naam);

Type Functions

FunctionParametersReturnsDescription
dhoronvaluestringGet type of value
lipivaluestringConvert to string
sonkhavaluenumberConvert to number
1// Type checking
2dekho(dhoron(42)); // "int"
3dekho(dhoron(3.14)); // "float"
4dekho(dhoron("hello")); // "string"
5dekho(dhoron(sotti)); // "boolean"
6dekho(dhoron([1,2,3])); // "array"
7dekho(dhoron({x:1})); // "map"
8
9// Convert to string
10dekho(lipi(42)); // "42"
11dekho(lipi(sotti)); // "true"
12
13// Convert to number
14dekho(sonkha("123")); // 123
15dekho(sonkha("3.14")); // 3.14

String Functions

FunctionParametersReturnsDescription
dorghyostrintGet string length
boroHaterstrstringConvert to uppercase
chotoHaterstrstringConvert to lowercase
bhagstr, separraySplit string by separator
joroarr, sepstringJoin array elements
chhantostrstringTrim whitespace
khojostr, substrintFind index of substring (-1 if not found)
angshostr, start, [end]stringGet substring
bodlostr, old, newstringReplace all occurrences
1dhoro str = " Hello World ";
2
3dekho(dorghyo(str)); // 15
4dekho(chhanto(str)); // "Hello World"
5dekho(boroHater("hello")); // "HELLO"
6dekho(chotoHater("HELLO")); // "hello"
7dekho(bhag("a,b,c", ",")); // ["a", "b", "c"]
8dekho(joro(["a","b","c"], "-"));// "a-b-c"
9dekho(khojo("hello", "ll")); // 2
10dekho(angsho("hello", 1, 4)); // "ell"
11dekho(bodlo("aaa", "a", "b")); // "bbb"

Array Functions

FunctionParametersReturnsDescription
dorghyoarrintGet array length
dhokaoarr, itemarrayPush item to end
berKoroarranyPop item from end
katoarr, start, [end]arraySlice array
ultoarrarrayReverse array
achearr, itembooleanCheck if item exists
sajaarrarraySort array
1dhoro arr = [3, 1, 4, 1, 5];
2
3dekho(dorghyo(arr)); // 5
4dhokao(arr, 9); // Push 9
5dekho(berKoro(arr)); // 9 (and removes it)
6dekho(kato(arr, 1, 3)); // [1, 4]
7dekho(ulto(arr)); // [5, 1, 4, 1, 3]
8dekho(ache(arr, 4)); // sotti
9dekho(saja([3,1,2])); // [1, 2, 3]

Math Functions

FunctionParametersReturnsDescription
borgomulnfloatSquare root
ghatbase, expnumberPower (base^exp)
nichenintFloor (round down)
uporenintCeiling (round up)
kachenintRound to nearest
nirateknnumberAbsolute value
choto...numsnumberMinimum value
boro...numsnumberMaximum value
lotto(none)floatRandom number [0, 1)
1dekho(borgomul(16)); // 4
2dekho(ghat(2, 10)); // 1024
3dekho(niche(3.7)); // 3
4dekho(upore(3.2)); // 4
5dekho(kache(3.5)); // 4
6dekho(niratek(-5)); // 5
7dekho(choto(5, 2, 8, 1)); // 1
8dekho(boro(5, 2, 8, 1)); // 8
9dekho(lotto()); // 0.xxxxx (random)

Map Functions

FunctionParametersReturnsDescription
chabimaparrayGet all keys as array
1dhoro obj = {naam: "Rahim", boyosh: 25};
2dekho(chabi(obj)); // ["naam", "boyosh"]

File I/O Functions

FunctionParametersReturnsDescription
poropathstringRead file content
lekhopath, contentbooleanWrite content to file
file_jogpath, contentbooleanAppend content to file (জোগ = add)
file_mochhopathbooleanDelete file (মোছো = erase)
file_nokolsource, destinationbooleanCopy file (নকল = duplicate)
folder_mochhopath, [recursive]booleanDelete folder (recursive if sotti/true)
file_dekhunpath, callbackwatcherWatch file for changes (দেখুন = watch)
file_dekhun_bondhowatcherbooleanStop watching file (বন্ধ = stop)
1// Read file
2dhoro content = poro("data.txt");
3dekho(content);
4
5// Write file
6lekho("output.txt", "Hello World");
7
8// Append to file
9file_jog("log.txt", "New log entry\n");
10
11// Copy file
12file_nokol("source.txt", "backup.txt");
13
14// Delete file
15file_mochho("temp.txt");
16
17// Delete folder (recursive)
18folder_mochho("old_data", sotti);
19
20// Watch file for changes
21dhoro watcher = file_dekhun("config.json", kaj(event, filename) {
22 dekho("File changed:", event, filename);
23 // Reload configuration
24});
25
26// Stop watching after 10 seconds
27ghumaao(10000).tarpor(kaj() {
28 file_dekhun_bondho(watcher);
29 dekho("Stopped watching");
30});

JSON Functions

FunctionParametersReturnsDescription
json_porostranyParse JSON string
json_banaovaluestringConvert to JSON string
1// Parse JSON
2dhoro obj = json_poro('{"name":"Rahim","age":25}');
3dekho(obj.name); // "Rahim"
4
5// Create JSON
6dhoro json = json_banao({x: 1, y: 2});
7dekho(json); // {"x":1,"y":2}

Environment Variables

See the Environment Variables Documentation for detailed examples and multi-environment setup.

FunctionParametersReturnsDescription
env_loadfilenamebooleanLoad environment variables from .env file
env_load_autoenvironmentstringAuto-load .env.{environment} or fallback to .env
env_getkeystringGet environment variable (error if not found)
env_get_defaultkey, defaultstringGet environment variable with default fallback
env_setkey, valuebooleanSet environment variable at runtime
env_all(none)mapGet all environment variables as map
env_clear(none)booleanClear all loaded environment variables
1// Load .env file
2env_load(".env");
3
4// Get environment variables
5dhoro api_key = env_get("API_KEY");
6dhoro api_url = env_get_default("API_URL", "http://localhost:3000");
7
8dekho("API URL:", api_url);
9
10// Multi-environment support
11env_load_auto("prod"); // Loads .env.prod or falls back to .env
12dhoro db_host = env_get("DB_HOST");
13dekho("Database Host:", db_host);
14
15// Set runtime variable
16env_set("SESSION_ID", "abc123");
17
18// Get all variables
19dhoro all = env_all();
20dekho("All env vars:", all);

Utility Functions

FunctionParametersReturnsDescription
somoy(none)intCurrent time in milliseconds
ghummskhaliSleep/delay for milliseconds
bondho[code](exit)Exit program
1// Current time
2dhoro now = somoy();
3dekho("Timestamp:", now);
4
5// Sleep 1 second
6dekho("Waiting...");
7ghum(1000);
8dekho("Done!");
9
10// Exit program
11bondho(0); // Exit with code 0

HTTP Functions

FunctionParametersReturnsDescription
server_chaluport, handlerkhaliStart HTTP server
anunurlmapHTTP GET request
uttorres, body, [status], [type]mapSend HTTP response
json_uttorres, data, [status]mapSend JSON response
1// Start server
2server_chalu(8080, kaj(req, res) {
3 json_uttor(res, {message: "Hello!"});
4});
5
6// Make HTTP request
7dhoro response = anun("https://api.example.com/data");
8dekho(response.body);

Async/Promise Functions

Asynchronous functions that return promises. Use with proyash/opekha keywords. See the Async/Await documentation for detailed examples.

FunctionParametersReturnsDescription
ghumaaomillisecondsPromiseSleep for specified time (async)
sob_proyasharrayPromiseWait for all promises concurrently (Promise.all)
poro_asyncpathPromiseRead file asynchronously
lekho_asyncpath, contentPromiseWrite file asynchronously
anun_asyncurlPromiseHTTP GET request asynchronously
1// Sleep for 1 second
2proyash kaj timer() {
3 dekho("Start");
4 opekha ghumaao(1000);
5 dekho("1 second later");
6}
7
8// Run multiple operations concurrently
9proyash kaj parallel() {
10 dhoro results = opekha sob_proyash([
11 ghumaao(500),
12 poro_async("file.txt"),
13 anun_async("https://api.example.com")
14 ]);
15 dekho("All operations complete!");
16}
17
18timer();
19parallel();

Networking Functions

BanglaCode provides comprehensive networking capabilities for TCP, UDP, and WebSocket protocols, making network programming as easy as JavaScript/Node.js.

TCP Functions (6 functions)

FunctionParametersReturnsDescription
tcp_server_chaluport, handlerkhaliStart TCP server with callback
tcp_juktohost, portPromiseConnect to TCP server (async)
tcp_pathaoconnection, datakhaliSend data on TCP connection
tcp_lekhoconnection, datakhaliWrite data to TCP connection (alias)
tcp_shunoconnectionPromiseRead data from TCP connection (async)
tcp_bondhoconnectionkhaliClose TCP connection
1// TCP Server
2tcp_server_chalu(8080, kaj(conn) {
3 dekho("Client:", conn["remote_addr"]);
4 dekho("Data:", conn["data"]);
5 tcp_pathao(conn, "Echo: " + conn["data"]);
6});
7
8// TCP Client
9proyash kaj client() {
10 dhoro conn = opekha tcp_jukto("localhost", 8080);
11 tcp_lekho(conn, "Hello!");
12 dhoro response = opekha tcp_shuno(conn);
13 dekho(response);
14 tcp_bondho(conn);
15}
16client();

UDP Functions (5 functions)

FunctionParametersReturnsDescription
udp_server_chaluport, handlerkhaliStart UDP server with callback
udp_pathaohost, port, dataPromiseSend UDP packet (async)
udp_uttorpacket, datakhaliSend UDP response to client
udp_shunoport, handlerkhaliListen for UDP packets (alias)
udp_bondhoconnectionkhaliClose UDP connection
1// UDP Server
2udp_server_chalu(9000, kaj(packet) {
3 dekho("From:", packet["remote_addr"]);
4 dekho("Data:", packet["data"]);
5 udp_uttor(packet, "Got it!");
6});
7
8// UDP Client
9proyash kaj send() {
10 opekha udp_pathao("localhost", 9000, "Hello UDP!");
11}
12send();

WebSocket Functions (4 functions)

FunctionParametersReturnsDescription
websocket_server_chaluport, handlerkhaliStart WebSocket server
websocket_juktourlPromiseConnect to WebSocket server (async)
websocket_pathaoconnection, messagekhaliSend WebSocket message
websocket_bondhoconnectionkhaliClose WebSocket connection
1// WebSocket Chat Server
2websocket_server_chalu(3000, kaj(conn) {
3 dekho("Message:", conn["message"]);
4 websocket_pathao(conn, "Reply: " + conn["message"]);
5});
6
7// WebSocket Client
8proyash kaj chat() {
9 dhoro ws = opekha websocket_jukto("ws://localhost:3000");
10 websocket_pathao(ws, "Hello WebSocket!");
11 ghumaao(1000);
12 websocket_bondho(ws);
13}
14chat();

Function Name Meanings

All built-in functions use Bengali words:

FunctionBengaliMeaning
dekhoদেখোlook/see (print)
naoনাওtake (input)
dhoronধরনtype/kind
lipiলিপিscript/writing (string)
sonkhaসংখ্যাnumber
dorghyoদৈর্ঘ্যlength
dhokaoঢোকাওinsert/push
berKoroবের করোtake out/pop
boroHaterবড় হাতেরuppercase
chotoHaterছোট হাতেরlowercase
borgomulবর্গমূলsquare root
somoyসময়time
poroপড়োread
lekhoলেখোwrite

System Operations

BanglaCode provides 53 system-level functions for file operations, process management, network information, system statistics, environment variables, and temporary file handling.

File Metadata

FunctionParametersReturnsDescription
file_akarpathnumberGet file size in bytes
file_permissionpathstringGet file permissions (e.g., "0644")
file_permission_setpath, permskhaliChange file permissions
file_malikanpathmapGet file owner (uid, gid, naam)
file_shomoy_poribortitopathnumberGet file modified time (Unix)
file_dhoronpathstringGet file type (file/directory/symlink)
file_renameold, newkhaliRename or move file

Directory Operations

FunctionParametersReturnsDescription
directory_taliikapatharrayList directory contents
directory_ghumaopatharrayRecursive directory traversal
directory_khali_kipathbooleanCheck if directory is empty
directory_akarpathnumberGet total directory size in bytes
1// File metadata example
2dhoro size = file_akar("/path/to/file.txt");
3dekho("Size:", size, "bytes");
4
5dhoro perms = file_permission("/path/to/file.txt");
6dekho("Permissions:", perms);
7
8// Directory operations
9dhoro files = directory_taliika("/home/user");
10ghuriye (dhoro i = 0; i < dorghyo(files); i = i + 1) {
11 dekho(files[i]);
12}

Process Management

FunctionParametersReturnsDescription
chalancmd, [args]mapExecute system command
process_ghummskhaliSleep for milliseconds
process_maropidkhaliKill process by PID
process_chalucmd, [args]mapStart process in background
process_opekhapidmapWait for process completion

Network Information

FunctionParametersReturnsDescription
network_interface-arrayGet all network interfaces
ip_addressifacearrayGet IP addresses for interface
ip_shokal-arrayGet all IP addresses
mac_addressifacestringGet MAC address for interface

System Statistics

FunctionParametersReturnsDescription
memory_total-numberTotal system memory in bytes
memory_bebohrito-numberUsed memory in bytes
disk_akar[path]numberTotal disk size in bytes
disk_mukt[path]numberFree disk space in bytes

Time Operations

FunctionParametersReturnsDescription
shomoy_ekhon-numberCurrent Unix timestamp
shomoy_formattimestamp, [format]stringFormat timestamp to string
shomoy_parsestr, [format]numberParse time string to timestamp
timezone-stringGet current timezone

Temporary Files

FunctionParametersReturnsDescription
temp_directory-stringGet system temp directory
temp_file[prefix]stringCreate temporary file
temp_folder[prefix]stringCreate temporary directory

Symbolic Links

FunctionParametersReturnsDescription
symlink_banaotarget, linkkhaliCreate symbolic link
symlink_porolinkstringRead symlink target
symlink_kipathbooleanCheck if path is symlink

Database Functions

Production-grade database connectors for PostgreSQL, MySQL, MongoDB, and Redis with connection pooling and async support. See the Database Documentation for detailed examples.

Universal Database Functions

FunctionParametersReturnsDescription
db_juktotype, configconnectionConnect to database (postgres/mysql/mongodb/redis)
db_jukto_asynctype, configpromiseConnect to database (async)
db_bandhoconnkhaliClose database connection
db_queryconn, sqlresultExecute SELECT query (SQL databases)
db_execconn, sqlresultExecute INSERT/UPDATE/DELETE
db_proshnoconn, sql, paramsresultPrepared statement (SQL injection safe)

Connection Pool Functions

FunctionParametersReturnsDescription
db_pool_banaotype, config, maxConnspoolCreate connection pool (50-100x faster)
db_pool_naopoolconnectionGet connection from pool
db_pool_ferotpool, connkhaliReturn connection to pool
db_pool_bondhopoolkhaliClose connection pool
db_pool_tothyopoolmapGet pool statistics

PostgreSQL Functions

FunctionParametersDescription
db_jukto_postgresconfigConnect to PostgreSQL
db_query_postgresconn, sqlExecute SELECT query
db_exec_postgresconn, sqlExecute INSERT/UPDATE/DELETE
db_proshno_postgresconn, sql, paramsPrepared statement
db_transaction_shuru_postgresconnBegin transaction
db_commit_postgrestxCommit transaction
db_rollback_postgrestxRollback transaction

MySQL Functions

FunctionParametersDescription
db_jukto_mysqlconfigConnect to MySQL
db_query_mysqlconn, sqlExecute SELECT query
db_exec_mysqlconn, sqlExecute INSERT/UPDATE/DELETE
db_proshno_mysqlconn, sql, paramsPrepared statement
db_transaction_shuru_mysqlconnBegin transaction
db_commit_mysqltxCommit transaction
db_rollback_mysqltxRollback transaction

MongoDB Functions

FunctionParametersDescription
db_jukto_mongodbconfigConnect to MongoDB
db_khojo_mongodbconn, collection, filterFind documents
db_dhokao_mongodbconn, collection, docInsert document
db_update_mongodbconn, collection, filter, updateUpdate documents
db_mujhe_mongodbconn, collection, filterDelete documents

Redis Functions

FunctionParametersDescription
db_jukto_redisconfigConnect to Redis
db_set_redisconn, key, value, ttl?Set key-value (optional TTL)
db_get_redisconn, keyGet value by key
db_del_redisconn, keyDelete key
db_expire_redisconn, key, secondsSet expiration time
db_lpush_redisconn, key, valuePush to list (left/front)
db_rpush_redisconn, key, valuePush to list (right/back)
db_lpop_redisconn, keyPop from list (left/front)
db_hset_redisconn, key, field, valueSet hash field
db_hget_redisconn, key, fieldGet hash field
db_hgetall_redisconn, keyGet all hash fields