Complete reference for all Codesi built-in functions.
- Input/Output
- Math Functions
- Type Functions
- Type Conversion
- String Methods
- Array Methods
- Object Methods
- File Operations
- JSON Operations
- Time Functions
- Special Features
Print values to console.
likho("Hello World")
likho("Name:", naam, "Age:", umra)
likho(x, y, z)
Parameters: Any number of values
Returns: khaali (None)
Special Behavior:
- Multiple values are separated by spaces
- Booleans are printed as
sach(true) orjhooth(false) khaali(null/none) is printed as the word "khaali"- Arrays and objects are formatted with brackets and braces
Examples:
likho(sach, jhooth) // Output: sach jhooth
likho(khaali) // Output: khaali
likho([1, 2, 3]) // Output: [1, 2, 3]
likho({naam: "Raj"}) // Output: {naam: Raj}
Get string input from user.
naam = input_lo("Aapka naam: ")
message = input_lo() // No prompt
Parameters:
prompt(optional): String to display Returns: String entered by user
Get integer input from user.
umra = int_lo("Aapki umra: ")
number = int_lo("Enter number: ")
Parameters:
prompt(optional): String to display Returns: Integer value Throws: Error if input is not a valid integer
Get float/decimal input from user.
height = float_lo("Height in meters: ")
price = float_lo("Enter price: ")
Parameters:
prompt(optional): String to display Returns: Float value Throws: Error if input is not a valid number
Get absolute value.
likho(math_absolute(-10)) // 10
likho(math_absolute(5)) // 5
Parameters: Number
Returns: Absolute value (always positive)
Get square root.
likho(math_square(16)) // 4.0
likho(math_square(25)) // 5.0
likho(math_square(2)) // 1.414...
Parameters: Non-negative number
Returns: Square root
Throws: Error if negative number
Calculate power.
likho(math_power(2, 3)) // 8
likho(math_power(5, 2)) // 25
likho(math_power(10, 0)) // 1
Parameters:
base: Base numberexponent: Power to raise to Returns: Result of base^exponent
Generate random integer.
dice = math_random(1, 6) // 1 to 6
lottery = math_random(1, 100) // 1 to 100
coin = math_random(0, 1) // 0 or 1
Parameters:
min: Minimum value (inclusive)max: Maximum value (inclusive) Returns: Random integer between min and max
Floor function (round down).
likho(math_niche(4.7)) // 4
likho(math_niche(4.2)) // 4
likho(math_niche(-2.7)) // -3
Parameters: Number
Returns: Largest integer β€ number
Ceiling function (round up).
likho(math_upar(4.2)) // 5
likho(math_upar(4.7)) // 5
likho(math_upar(-2.3)) // -2
Parameters: Number
Returns: Smallest integer β₯ number
Round to specified decimal places.
likho(math_gol(4.567)) // 5
likho(math_gol(4.567, 2)) // 4.57
likho(math_gol(4.567, 1)) // 4.6
Parameters:
number: Number to rounddecimals(optional): Decimal places (default: 0) Returns: Rounded number
// Sine, Cosine, Tangent
math_sin(angle_in_radians)
math_cos(angle_in_radians)
math_tan(angle_in_radians)
// Example
pi = 3.14159
likho(math_sin(pi / 2)) // 1.0
likho(math_cos(0)) // 1.0
// Natural logarithm (base e)
math_log(number)
// Exponential (e^x)
math_exp(number)
// Examples
likho(math_log(2.71828)) // β 1.0
likho(math_exp(1)) // β 2.71828
Get type of value.
likho(prakar(10)) // "Integer"
likho(prakar(3.14)) // "Float/Decimal"
likho(prakar("hello")) // "shabd"
likho(prakar([1, 2])) // "array"
likho(prakar({a: 1})) // "object"
likho(prakar(sach)) // "sach_jhooth"
likho(prakar(khaali)) // "khaali"
Parameters: Any value
Returns: String representing type
// Check if value is specific type
string_hai(value) // Is string?
array_hai(value) // Is array?
int_hai(value) // Is integer?
float_hai(value) // Is float?
bool_hai(value) // Is boolean?
obj_hai(value) // Is object?
// Examples
agar (string_hai(naam)) {
likho("It's a string!")
}
agar (array_hai(data)) {
likho("It's an array!")
}
Parameters: Any value
Returns: sach or jhooth
Convert to string.
text = string_bnao(123) // "123"
text = string_bnao(3.14) // "3.14"
text = string_bnao(sach) // "sach"
text = string_bnao([1, 2]) // "[1, 2]"
Parameters: Any value
Returns: String representation
Convert to integer.
num = int_bnao("123") // 123
num = int_bnao(3.14) // 3
num = int_bnao(3.99) // 3
num = int_bnao("45.67") // 45 (parses as float first)
Parameters: String or number
Returns: Integer value
Throws: Error if conversion fails
Convert to float.
num = float_bnao("3.14") // 3.14
num = float_bnao(5) // 5.0
num = float_bnao("42") // 42.0
Parameters: String or number
Returns: Float value
Throws: Error if conversion fails
Convert to boolean.
likho(bool_bnao(1)) // sach
likho(bool_bnao(0)) // jhooth
likho(bool_bnao("text")) // sach
likho(bool_bnao("")) // jhooth
Parameters: Any value
Returns: sach or jhooth
Get string length.
text = "Hello"
likho(text.lambai()) // 5
Returns: Integer length
Convert to uppercase.
text = "hello world"
likho(text.bada_karo()) // "HELLO WORLD"
Returns: Uppercase string
Convert to lowercase.
text = "HELLO WORLD"
likho(text.chota_karo()) // "hello world"
Returns: Lowercase string
Remove leading/trailing whitespace.
text = " hello "
likho(text.saaf_karo()) // "hello"
Returns: Trimmed string
Split string into array.
text = "apple,banana,orange"
fruits = text.todo(",")
likho(fruits) // ["apple", "banana", "orange"]
// Default separator is space
words = "hello world".todo()
likho(words) // ["hello", "world"]
Parameters: Separator string (optional)
Returns: Array of strings
Replace first occurrence.
text = "hello world world"
result = text.badlo("world", "codesi")
likho(result) // "hello codesi world"
Parameters:
old: String to findnew: Replacement string Returns: Modified string
Replace all occurrences.
text = "hello world world"
result = text.sab_badlo("world", "codesi")
likho(result) // "hello codesi codesi"
Parameters:
old: String to findnew: Replacement string Returns: Modified string
Check if substring exists.
text = "hello world"
likho(text.included_hai("world")) // sach
likho(text.included_hai("xyz")) // jhooth
Parameters: Substring to search
Returns: sach or jhooth
Check if starts with prefix.
text = "hello world"
likho(text.start_hota_hai("hello")) // sach
likho(text.start_hota_hai("world")) // jhooth
Parameters: Prefix string
Returns: sach or jhooth
Check if ends with suffix.
text = "hello world"
likho(text.end_hota_hai("world")) // sach
likho(text.end_hota_hai("hello")) // jhooth
Parameters: Suffix string
Returns: sach or jhooth
Note: Most array methods support both English and Hindi names for flexibility!
Add element to end of array.
arr = [1, 2, 3]
arr.push(4) // English version
likho(arr) // [1, 2, 3, 4]
// Or use Hindi version
arr.dalo(5)
likho(arr) // [1, 2, 3, 4, 5]
Aliases: push, dalo
Parameters: Element to add
Returns: Modified array
Remove and return last element.
arr = [1, 2, 3]
last = arr.pop() // English version
likho(last) // 3
likho(arr) // [1, 2]
// Or use Hindi version
last = arr.nikalo()
Aliases: pop, nikalo
Returns: Removed element
Remove and return first element.
arr = [1, 2, 3]
first = arr.shift() // English version
likho(first) // 1
likho(arr) // [2, 3]
// Or use Hindi version
first = arr.pehla_nikalo()
Aliases: shift, pehla_nikalo
Returns: Removed element
Add element to beginning of array.
arr = [2, 3, 4]
arr.unshift(1) // English version
likho(arr) // [1, 2, 3, 4]
// Or use Hindi version
arr.pehle_dalo(0)
likho(arr) // [0, 1, 2, 3, 4]
Aliases: unshift, pehle_dalo
Parameters: Element to add
Returns: Modified array
Get array length.
arr = [1, 2, 3, 4, 5]
likho(arr.lambai()) // 5 (Hindi)
likho(arr.size()) // 5 (English)
Aliases: lambai, size
Returns: Integer length
Transform each element.
numbers = [1, 2, 3, 4, 5]
doubled = numbers.map(lambda(x) -> x * 2)
likho(doubled) // [2, 4, 6, 8, 10]
// With named function
karya square(x) {
vapas x * x
}
squared = numbers.map(square)
likho(squared) // [1, 4, 9, 16, 25]
// Hindi version also works
doubled = numbers.badlo(lambda(x) -> x * 2)
Aliases: map, badlo
Parameters: Function to apply to each element
Returns: New array with transformed elements
Filter elements based on condition.
numbers = [1, 2, 3, 4, 5, 6]
even = numbers.filter(lambda(x) -> x % 2 == 0)
likho(even) // [2, 4, 6]
// Hindi version
even = numbers.chuno(lambda(x) -> x % 2 == 0)
// Complex filtering
students = [
{naam: "Raj", marks: 85},
{naam: "Priya", marks: 92},
{naam: "Amit", marks: 78}
]
toppers = students.filter(lambda(s) -> s.marks >= 90)
Aliases: filter, chuno
Parameters: Function returning boolean
Returns: New array with filtered elements
Reduce array to single value.
numbers = [1, 2, 3, 4, 5]
// Sum all numbers (English)
sum = numbers.reduce(lambda(acc, x) -> acc + x, 0)
likho(sum) // 15
// Hindi version
sum = numbers.combine(lambda(acc, x) -> acc + x, 0)
likho(sum) // 15
// Product
product = numbers.reduce(lambda(acc, x) -> acc * x, 1)
likho(product) // 120
// Without initial value (uses first element)
sum = numbers.reduce(lambda(acc, x) -> acc + x)
likho(sum) // 15
Aliases: reduce, combine
Parameters:
function: Accumulator function (acc, current)initial(optional): Starting value Returns: Final accumulated value
Join array elements into string.
arr = ["apple", "banana", "orange"]
text = arr.join(", ") // English
likho(text) // "apple, banana, orange"
// Hindi version
text = arr.jodo(", ")
likho(text) // "apple, banana, orange"
// Default separator is comma
numbers = [1, 2, 3]
likho(numbers.join()) // "1,2,3"
Aliases: join, jodo
Parameters: Separator string (default: ",")
Returns: Joined string
Extract portion of array.
arr = [1, 2, 3, 4, 5]
subset = arr.slice(1, 4) // English
likho(subset) // [2, 3, 4]
// Hindi version
subset = arr.cutkr(1, 4)
likho(subset) // [2, 3, 4]
// From index to end
end_part = arr.slice(2)
likho(end_part) // [3, 4, 5]
Aliases: slice, cutkr
Parameters:
start: Starting indexend(optional): Ending index (exclusive) Returns: New array (doesn't modify original)
Reverse array in place.
arr = [1, 2, 3, 4, 5]
arr.reverse() // English
likho(arr) // [5, 4, 3, 2, 1]
// Hindi version also works
arr = [1, 2, 3, 4, 5]
arr.ulta()
likho(arr) // [5, 4, 3, 2, 1]
Aliases: reverse, ulta
Returns: Reversed array (modifies original)
Sort array in place.
arr = [5, 2, 8, 1, 9]
arr.sort() // English
likho(arr) // [1, 2, 5, 8, 9]
// Hindi version
arr = [5, 2, 8, 1, 9]
arr.arrange()
likho(arr) // [1, 2, 5, 8, 9]
// Strings
names = ["Raj", "Amit", "Priya"]
names.sort()
likho(names) // ["Amit", "Priya", "Raj"]
Aliases: sort, arrange
Returns: Sorted array (modifies original)
Get all keys as array.
person = {naam: "Raj", umra: 25, city: "Mumbai"}
keys = person.keys()
likho(keys) // ["naam", "umra", "city"]
Returns: Array of keys
Get all values as array.
person = {naam: "Raj", umra: 25, city: "Mumbai"}
values = person.values()
likho(values) // ["Raj", 25, "Mumbai"]
Returns: Array of values
Get key-value pairs as array of arrays.
person = {naam: "Raj", umra: 25}
items = person.items()
likho(items) // [["naam", "Raj"], ["umra", 25]]
// Iterate over items
har item mein items {
likho(item[0], ":", item[1])
}
Returns: Array of [key, value] pairs
Check if key exists.
person = {naam: "Raj", umra: 25}
likho(person.hai_kya("naam")) // sach
likho(person.hai_kya("city")) // jhooth
Parameters: Key to check
Returns: sach or jhooth
Read file contents.
content = file_padho("data.txt")
likho(content)
// Error handling
try {
content = file_padho("missing.txt")
} catch (e) {
likho("Error:", e.message)
}
Parameters: File path (string)
Returns: File contents as string
Throws: Error if file not found
Write to file (overwrites existing).
file_likho("output.txt", "Hello World")
file_likho("data.txt", "Line 1\nLine 2\nLine 3")
// Write array/object (converts to string)
data = [1, 2, 3]
file_likho("numbers.txt", string_bnao(data))
Parameters:
path: File pathcontent: Content to write Returns:sachon success
Throws: Error on failure
Append to file.
file_append("log.txt", "New log entry\n")
file_append("data.txt", "Additional line")
Parameters:
path: File pathcontent: Content to append Returns:sachon success
Throws: Error on failure
Check if file exists.
agar (file_hai("config.txt")) {
content = file_padho("config.txt")
} nahi_to {
likho("File not found")
}
Parameters: File path
Returns: sach or jhooth
Delete file.
agar (file_hai("temp.txt")) {
file_delete("temp.txt")
likho("File deleted")
}
Parameters: File path
Throws: Error if file doesn't exist
Copy file.
file_copy("original.txt", "backup.txt")
Parameters:
source: Source file pathdestination: Destination file path Throws: Error on failure
Move/rename file.
file_move("old_name.txt", "new_name.txt")
Parameters:
source: Source file pathdestination: Destination file path Throws: Error on failure
Get file size in bytes.
size = file_size("data.txt")
likho("File size:", size, "bytes")
Parameters: File path
Returns: Size in bytes
Throws: Error if file doesn't exist
Create directory.
dir_banao("output")
dir_banao("data/processed")
Parameters: Directory path
Throws: Error on failure
List directory contents.
files = dir_list(".")
har file mein files {
likho(file)
}
// Specific directory
files = dir_list("data")
Parameters: Directory path (default: ".")
Returns: Array of file/folder names
Parse JSON string to object/array.
json_text = '{"naam": "Raj", "umra": 25}'
data = json_parse(json_text)
likho(data.naam) // "Raj"
// Array
json_arr = '[1, 2, 3, 4, 5]'
numbers = json_parse(json_arr)
likho(numbers[0]) // 1
Parameters: JSON string
Returns: Parsed object or array
Throws: Error if invalid JSON
Convert value to JSON string.
person = {naam: "Raj", umra: 25, city: "Mumbai"}
json_text = json_stringify(person)
likho(json_text)
// {"naam": "Raj", "umra": 25, "city": "Mumbai"}
// Save to file
file_likho("person.json", json_stringify(person))
Parameters: Any value (object, array, etc.)
Returns: JSON string
Get current timestamp.
timestamp = time_now()
likho(timestamp) // Unix timestamp (seconds since 1970)
// Measure execution time
start = time_now()
// ... some code ...
end = time_now()
duration = end - start
likho("Time taken:", duration, "seconds")
Returns: Float (seconds since epoch)
Pause execution.
likho("Starting...")
time_sleep(2) // Wait 2 seconds
likho("Done!")
// Countdown
har i se 5 tak 0 {
likho(i)
time_sleep(1)
}
likho("Blast off!")
Parameters: Seconds to sleep (can be decimal)
Returns: khaali
Get length of string/array.
likho(lambai("hello")) // 5
likho(lambai([1, 2, 3])) // 3
Parameters: String or array
Returns: Length
Create array of numbers.
// Single argument (0 to n)
nums = range(5)
likho(nums) // [0, 1, 2, 3, 4]
// Two arguments (start to end)
nums = range(5, 10)
likho(nums) // [5, 6, 7, 8, 9]
// Use in loops
har i mein range(1, 6) {
likho(i) // 1, 2, 3, 4, 5
}
Parameters:
start: Start value (or end if only one arg)end(optional): End value (exclusive) Returns: Array of integers
Repeat string.
likho(repeatkr("*", 5)) // "*****"
likho(repeatkr("Ha", 3)) // "HaHaHa"
line = repeatkr("-", 50)
Parameters:
string: String to repeatcount: Number of repetitions Returns: Repeated string
Enable code explanation mode.
samjhao_on()
// Now every operation will be explained
x = 10
y = 20
result = x + y
Returns: Success message
Disable code explanation mode.
samjhao_off()
Returns: Success message
Display collected explanations.
samjhao_on()
x = 10
y = 20
result = x + y
samjhao() // Shows detailed explanation
Returns: Formatted explanation text
Enable time-travel debugging.
time_machine_on() // Default: 100 snapshots
time_machine_on(500) // Custom limit
x = 5
x = x * 2
x = x + 3
Parameters:
max(optional): Max snapshots (default: 100) Returns: Success message
Disable time machine.
time_machine_off()
Returns: Success message
Check time machine status.
time_machine_status()
// Shows: ON/OFF, snapshots count, current step
Returns: Status information
Go back in execution history.
x = 5
x = 10
x = 15
peeche() // Go back to x = 10
peeche(2) // Go back 2 steps to x = 5
Parameters:
steps(optional): Number of steps (default: 1) Returns: Snapshot information
Note: Only works in REPL with time machine enabled
Go forward in execution history.
aage() // Go forward 1 step
aage(2) // Go forward 2 steps
Parameters:
steps(optional): Number of steps (default: 1) Returns: Snapshot information
Note: Only works in REPL with time machine enabled
View complete execution timeline.
timeline()
// Shows all snapshots with step numbers
Returns: Complete timeline display
Import another Codesi file.
// Import and execute another file
import_karo("utils.cds")
// Now you can use functions from utils.cds
Parameters: File path to import
Returns: sach on success
Throws: Error if file not found
likho,input_lo,int_lo,float_lo
math_absolute,math_square,math_power,math_randommath_niche,math_upar,math_golmath_sin,math_cos,math_tanmath_log,math_exp
prakar/type_ofstring_hai,array_hai,int_hai,float_hai,bool_hai,obj_haistring_bnao,int_bnao,float_bnao,bool_bnao
lambai,bada_karo,chota_karo,saaf_karotodo,badlo,sab_badloincluded_hai,start_hota_hai,end_hota_hai
push,pop,shift,unshiftlambai,map,filter,reducejoin,slice,reverse,sort
keys,values,items,hai_kya
file_padho,file_likho,file_appendfile_hai,file_delete,file_copy,file_move,file_sizedir_banao,dir_list
json_parse,json_stringify
time_now,time_sleep
samjhao_on,samjhao_off,samjhaotime_machine_on,time_machine_off,time_machine_statuspeeche,aage,timeline
lambai,range,repeatkr
import_karo
Total: 70+ Built-in Functions!
Next: Control Flow Guide