Built-ins › Built-in Functionsv0.1
Built-ins

Built-in Functions

All built-in functions available without import. Call them directly in any .pseudo file.

List Operations

FunctionDescriptionExample
len(arr)Length of listlen([1,2,3]) → 3
append(arr, item)Add item to endappend(arr, 5)
prepend(arr, item)Add item to frontprepend(arr, 0)
remove(arr, item)Remove first occurrenceremove(arr, 3)
pop(arr)Remove & return lastpop([1,2,3]) → 3
pop(arr, i)Remove & return at index ipop(arr, 0) → first
insert(arr, i, item)Insert item at index iinsert(arr, 1, 99)
sort(arr)Sort in placesort(arr)
sorted(arr)New sorted list (original unchanged)sorted([3,1,2]) → [1,2,3]
reverse(arr)Reverse in placereverse(arr)
reversed(arr)New reversed listreversed([1,2,3]) → [3,2,1]
index(arr, item)Index of first occurrence (-1 if not found)index(arr, 5)
count(arr, item)Count occurrencescount(arr, 3)
sum(arr)Sum all elementssum([1,2,3]) → 6
min(arr)Minimum valuemin([3,1,2]) → 1
max(arr)Maximum valuemax([3,1,2]) → 3
min(a, b)Minimum of two valuesmin(3, 5) → 3
max(a, b)Maximum of two valuesmax(3, 5) → 5
range(n)List 0 to n-1range(5) → [0,1,2,3,4]
range(start, end)List start to end-1range(2, 5) → [2,3,4]
range(start, end, step)List with steprange(0,10,2) → [0,2,4,6,8]
flatten(arr)Flatten nested listflatten([[1,2],[3]]) → [1,2,3]
zip(a, b)Zip two listszip([1,2],[3,4]) → [[1,3],[2,4]]
enumerate(arr)List of [i, val] pairsenumerate(["a","b"]) → [[0,"a"],[1,"b"]]
copy(arr)Shallow copy of listcopy(arr)

Example

pseudo
arr = [5, 2, 8, 1, 9]
sort(arr)
print arr               # → [1, 2, 5, 8, 9]

top3 = sorted(arr, true)[0:3]   # descending, first 3
print top3              # → [9, 8, 5]

print sum(arr)          # → 25
print min(arr)          # → 1
print max(arr)          # → 9

String Operations

FunctionDescriptionExample
len(str)Length of stringlen("hello") → 5
upper(str)Convert to uppercaseupper("hi") → "HI"
lower(str)Convert to lowercaselower("HI") → "hi"
strip(str)Remove leading/trailing whitespacestrip(" hi ") → "hi"
split(str)Split by whitespace → listsplit("a b c") → ["a","b","c"]
split(str, delim)Split by delimitersplit("a,b", ",") → ["a","b"]
join(arr, delim)Join list into stringjoin(["a","b"], ",") → "a,b"
replace(str, old, new)Replace substringreplace("hello","l","r") → "herro"
contains(str, sub)True if substring foundcontains("hello","ell") → true
startswith(str, prefix)True if starts with prefixstartswith("hello","he") → true
endswith(str, suffix)True if ends with suffixendswith("hello","lo") → true
substring(str, start, end)Substring by index rangesubstring("hello",1,4) → "ell"
ord(str)ASCII code of first characterord("A") → 65
chr(n)Character from ASCII codechr(65) → "A"
isdigit(str)True if all digitsisdigit("123") → true
isalpha(str)True if all lettersisalpha("abc") → true

Example

pseudo
s = "Hello, World!"
print upper(s)            # → HELLO, WORLD!
print lower(s)            # → hello, world!
parts = split(s, ", ")
print parts               # → ["Hello", "World!"]
print join(parts, " - ") # → Hello - World!

Math Functions

Function / ConstantDescriptionExample
abs(x)Absolute valueabs(-5) → 5
round(x)Round to nearest integerround(3.7) → 4
round(x, n)Round to n decimal placesround(3.14159, 2) → 3.14
floor(x)Round downfloor(3.9) → 3
ceil(x)Round upceil(3.1) → 4
sqrt(x)Square rootsqrt(16) → 4.0
pow(x, n)x to the power npow(2, 10) → 1024
log(x)Natural logarithmlog(e) → 1.0
log(x, base)Log with given baselog(8, 2) → 3.0
log2(x)Base-2 logarithmlog2(8) → 3.0
log10(x)Base-10 logarithmlog10(100) → 2.0
sin(x) / cos(x) / tan(x)Trigonometric (radians)sin(pi/2) → 1.0
gcd(a, b)Greatest common divisorgcd(12, 8) → 4
lcm(a, b)Least common multiplelcm(4, 6) → 12
factorial(n)n!factorial(5) → 120
piConstant π = 3.14159...-
eConstant e = 2.71828...-

Type Conversion

FunctionDescriptionExample
int(x)Convert to integerint("42") → 42
float(x)Convert to floatfloat("3.14") → 3.14
str(x)Convert to stringstr(42) → "42"
list(x)Convert to listlist(range(3)) → [0,1,2]
bool(x)Convert to booleanbool(0) → false

Type Checking

FunctionReturns
is_number(x)true if x is a number
is_string(x)true if x is a string
is_list(x)true if x is a list
is_bool(x)true if x is boolean
is_null(x)true if x is null
type(x)"number", "string", "list", "bool", "null", or class name

Example

pseudo
x = 42
print type(x)         # → number
print is_number(x)    # → true
print is_string(x)    # → false

y = "hello"
print type(y)         # → string

Utility

FunctionDescription
print(x)Explicit print (also auto-print works)
assert(cond, msg)Throw AssertionError if condition is false