Skip to main content

Built-in Functions

Uddin-Lang provides a comprehensive set of built-in functions to help you build powerful applications efficiently.

Type Conversion Functions

FunctionDescriptionExampleReturn Type
str(value)Convert to stringstr(42)"42"string
int(value)Convert to integerint("42")42int
float(value)Convert to floatfloat("3.14")3.14float
bool(value)Convert to booleanbool(1)truebool
char(value)Convert to characterchar(65)"A"string
rune(value)Convert to Unicode runerune("A")65int
type(value)Get type nametype(42)"int"string
typeof(value)Get detailed type infotypeof([1,2,3])"array[int]"string

String Functions

Basic String Operations

FunctionDescriptionExampleReturn Type
len(string)String lengthlen("hello")5int
substr(string, start, length)Extract substringsubstr("hello", 1, 3)"ell"string
split(string, delimiter)Split stringsplit("a,b,c", ",")["a","b","c"]array
join(array, delimiter)Join array to stringjoin(["a","b"], ",")"a,b"string
trim(string)Remove whitespacetrim(" hello ")"hello"string
replace(string, old, new)Replace substringreplace("hello", "l", "x")"hexxo"string

String Case Functions

FunctionDescriptionExampleReturn Type
upper(string)Convert to uppercaseupper("hello")"HELLO"string
lower(string)Convert to lowercaselower("HELLO")"hello"string

String Search Functions

FunctionDescriptionExampleReturn Type
contains(string, substring)Check if containscontains("hello", "ell")truebool
starts_with(string, prefix)Check prefixstarts_with("hello", "he")truebool
ends_with(string, suffix)Check suffixends_with("hello", "lo")truebool

Array Functions

Core Array Functions

FunctionDescriptionExampleReturn Type
len(array)Array lengthlen([1,2,3])3int
append(array, items...)Add itemsappend([1,2], 3, 4)[1,2,3,4]array
slice(array, start, end)Extract sliceslice([1,2,3,4], 1, 3)[2,3]array
sort(array)Sort in placesort([3,1,2])[1,2,3]array
range(n) or range(start, stop)Create rangerange(3)[0,1,2]
range(1, 4)[1,2,3]
array
find(array, value)Find indexfind([1,2,3], 2)1int
contains(array, value)Check membershipcontains([1,2,3], 2)truebool

Functional Programming Methods

FunctionDescriptionExample
map(array, function)Transform each elementmap([1,2,3], fun(x): return x*2 end)[2,4,6]
filter(array, function)Filter elements by conditionfilter([1,2,3,4], fun(x): return x%2==0 end)[2,4]
reduce(array, function, init)Reduce to single valuereduce([1,2,3], fun(a,x): return a+x end, 0)6
reverse(array)Reverse array in-placereverse([1,2,3]) modifies to [3,2,1]
push(array, element)Add element to endpush([1,2], 3) modifies to [1,2,3]
pop(array)Remove and return last elementpop([1,2,3])3, array becomes [1,2]
shift(array)Remove and return first elementshift([1,2,3])1, array becomes [2,3]
unshift(array, element)Add element to beginningunshift([2,3], 1) modifies to [1,2,3]
index_of(array, element)Find first index of elementindex_of([1,2,3,2], 2)1
last_index_of(array, element)Find last index of elementlast_index_of([1,2,3,2], 2)3

Data Structures

Set (Unique Collection)

FunctionDescriptionExample
set_new()Create new empty setmy_set = set_new()
set_add(set, elem)Add element (ignores duplicates)set_add(my_set, 1)
set_has(set, elem)Check if element existsset_has(my_set, 1)true
set_remove(set, elem)Remove elementset_remove(my_set, 1)true
set_size(set)Get number of elementsset_size(my_set)3
set_to_array(set)Convert set to arrayset_to_array(my_set)[1,2,3]

Stack (LIFO - Last In, First Out)

FunctionDescriptionExample
stack_new()Create new empty stackmy_stack = stack_new()
stack_push(stack, elem)Add element to topstack_push(my_stack, "item")
stack_pop(stack)Remove and return top elementstack_pop(my_stack)"item"
stack_peek(stack)View top element without removingstack_peek(my_stack)"item"
stack_size(stack)Get number of elementsstack_size(my_stack)3
stack_empty(stack)Check if stack is emptystack_empty(my_stack)false

Queue (FIFO - First In, First Out)

FunctionDescriptionExample
queue_new()Create new empty queuemy_queue = queue_new()
queue_enqueue(queue, elem)Add element to backqueue_enqueue(my_queue, "task")
queue_dequeue(queue)Remove and return front elementqueue_dequeue(my_queue)"task"
queue_front(queue)View front element without removingqueue_front(my_queue)"task"
queue_size(queue)Get number of elementsqueue_size(my_queue)3
queue_empty(queue)Check if queue is emptyqueue_empty(my_queue)false

Math Functions

Basic Math Operations

FunctionDescriptionExampleReturn Type
abs(x)Absolute valueabs(-5)5int/float
max(a, b, ...)Maximum valuemax(1, 5, 3)5int/float
min(a, b, ...)Minimum valuemin(1, 5, 3)1int/float
pow(base, exp)Power functionpow(2, 3)8int/float
sqrt(x)Square rootsqrt(16)4.0float
cbrt(x)Cube rootcbrt(27)3.0float

Rounding Functions

FunctionDescriptionExampleReturn Type
round(x)Round to nearest integerround(3.7)4int
round(x, n)Round to n decimal placesround(3.14159, 2)3.14float
floor(x)Round down (floor)floor(3.7)3int
ceil(x)Round up (ceiling)ceil(3.2)4int
trunc(x)Truncate decimal parttrunc(3.7)3int

Trigonometric Functions

FunctionDescriptionExampleReturn Type
sin(x)Sine (radians)sin(PI/2)1.0float
cos(x)Cosine (radians)cos(0)1.0float
tan(x)Tangent (radians)tan(PI/4)1.0float
asin(x)Arc sine (returns radians)asin(1)1.5708float
acos(x)Arc cosine (returns radians)acos(1)0.0float
atan(x)Arc tangent (returns radians)atan(1)0.7854float
atan2(y, x)Arc tangent of y/xatan2(1, 1)0.7854float

Hyperbolic Functions

FunctionDescriptionExampleReturn Type
sinh(x)Hyperbolic sinesinh(1.0)1.175float
cosh(x)Hyperbolic cosinecosh(1.0)1.543float
tanh(x)Hyperbolic tangenttanh(1.0)0.762float

Logarithmic Functions

FunctionDescriptionExampleReturn Type
log(x)Natural logarithm (ln)log(E)1.0float
log10(x)Base-10 logarithmlog10(100)2.0float
log2(x)Base-2 logarithmlog2(8)3.0float
logb(x, base)Logarithm with custom baselogb(125, 5)3.0float
exp(x)Exponential function (e^x)exp(1)2.718...float
exp2(x)Base-2 exponential (2^x)exp2(3)8.0float

Statistical Functions

FunctionDescriptionExampleReturn Type
sum(array)Sum of array elementssum([1, 2, 3, 4])10int/float
mean(array)Arithmetic mean (average)mean([1, 2, 3, 4])2.5float
median(array)Median valuemedian([1, 2, 3, 4, 5])3.0float
mode(array)Most frequent valuemode([1, 2, 2, 3])2any
std_dev(array)Standard deviationstd_dev([1, 2, 3, 4])1.29float
variance(array)Variancevariance([1, 2, 3, 4])1.67float

Number Theory Functions

FunctionDescriptionExampleReturn Type
gcd(a, b)Greatest common divisorgcd(12, 8)4int
lcm(a, b)Least common multiplelcm(12, 8)24int
factorial(n)Factorial (n!)factorial(5)120int
fibonacci(n)Nth Fibonacci numberfibonacci(7)13int
is_prime(n)Check if number is primeis_prime(17)truebool
prime_factors(n)List of prime factorsprime_factors(12)[2,2,3]array

Random Number Functions

FunctionDescriptionExampleReturn Type
random()Random float between 0 and 1random()0.7234float
random_int(min, max)Random integer in rangerandom_int(1, 10)7int
random_float(min, max)Random float in rangerandom_float(1.0, 2.0)1.45float
random_choice(array)Random element from arrayrandom_choice([1,2,3])2any
shuffle(array)Shuffle array in placeshuffle([1,2,3])[3,1,2]array
seed_random(seed)Set random seedseed_random(42)null

Mathematical Constants

ConstantDescriptionValue
PIPi (π)3.14159265359
EEuler's number (e)2.71828182846
TAUTau (2π)6.28318530718
PHIGolden ratio (φ)1.61803398875
LN2Natural logarithm of 20.69314718056
LN10Natural logarithm of 102.30258509299
SQRT2Square root of 21.41421356237
SQRT3Square root of 31.73205080757

I/O Functions

FunctionDescriptionExampleReturn Type
print(values...)Print to consoleprint("Hello", "World")void
input(prompt)Read user inputname = input("Enter name: ")string

XML Processing

FunctionDescriptionExample
xml_parse(xml_string)Parse XML string to Uddin-Lang valuedata = xml_parse('<person><name>John</name></person>')
xml_stringify(value)Convert Uddin-Lang value to XML stringxml_str = xml_stringify({person: {name: "Alice", age: "25"}})

XML Structure Mapping

XML FeatureUddin-Lang RepresentationExample
Root ElementMap key<root>...</root>{"root": {...}}
Child ElementsMap properties<name>John</name>{"name": "John"}
Attributes@attributes object<item id="1">{"@attributes": {"id": "1"}}
Text ContentString value<title>Book</title>{"title": "Book"}
Multiple ElementsArray<item>1</item><item>2</item>[1, 2]

Utility Functions

FunctionDescriptionExampleReturn Type
sign(x)Sign of number (-1, 0, 1)sign(-5)-1int
clamp(x, min, max)Clamp value to rangeclamp(15, 1, 10)10int/float
lerp(a, b, t)Linear interpolationlerp(0, 10, 0.5)5.0float
degrees(radians)Convert radians to degreesdegrees(PI)180.0float
radians(degrees)Convert degrees to radiansradians(180)3.14159float
is_nan(x)Check if value is NaNis_nan(0.0/0.0)truebool
is_infinite(x)Check if value is infiniteis_infinite(1.0/0.0)truebool

System Functions

FunctionDescriptionExampleReturn Type
exit(code)Exit program with codeexit(0)void

Functions Moved to Stdlib Modules

The following function groups have been moved to opt-in namespaced stdlib modules. They are no longer available as flat globals. Use import "module" to access them.

ModuleImportFunctions
fsimport "fs"fs.read, fs.write, fs.exists, fs.size, fs.modified, fs.permissions, fs.copy, fs.move, fs.delete, fs.mkdir, fs.rmdir, fs.list_dir, fs.path_join, fs.path_dirname, fs.path_basename, fs.path_ext, fs.getcwd, fs.chdir
jsonimport "json"json.parse, json.stringify
httpimport "http"http.get, http.post, http.put, http.delete, http.request, http.server_start, http.server_stop, http.server_route, http.response, http.tcp_connect, http.tcp_listen, http.tcp_accept, http.tcp_read, http.tcp_write, http.tcp_close, http.udp_connect, http.udp_listen, http.udp_read, http.udp_write, http.udp_close, http.net_resolve, http.net_ping
datetimeimport "datetime"datetime.now, datetime.time_now, datetime.sleep, datetime.format, datetime.parse, datetime.format_enhanced, datetime.add, datetime.subtract, datetime.diff, datetime.between, datetime.compare
regeximport "regex"regex.is_match, regex.match, regex.find, regex.find_all, regex.replace, regex.split
databaseimport "database"database.connect, database.query, database.exec, database.close, database.begin, database.commit, database.rollback, database.prepare, database.ping, database.stats
factimport "fact"fact.assert, fact.retract, fact.query, fact.exists, fact.count, fact.clear, fact.get_all
cdcimport "cdc"cdc.emit, cdc.define_pattern, cdc.get_window, cdc.clear, cdc.count
wafimport "waf"waf.header, waf.query, waf.body_contains, waf.cidr_match, waf.path_match, waf.score, waf.action, waf.detected, waf.detected_any, waf.detected_list, waf.return

See the Module System Reference for full documentation, function signatures, and examples.

For more detailed examples and advanced usage, see the Tutorial section.