Pepper Standard Library Reference

String Library (string)

upper()

Converts string to uppercase

LET up: string = upper FROM string "hello" _

lower()

Converts string to lowercase

LET low: string = lower FROM string "HELLO" _

len()

Returns length of string

LET length: int = len FROM string "hello" _

trim()

Removes leading/trailing whitespace

LET trimmed: string = trim FROM string " hello " _

replace(old, new)

Replaces all occurrences of 'old' with 'new'

LET replaced: string = replace FROM string "hello" ("l", "w")

split(delimiter)

Splits string into list by delimiter

LET parts: list = split FROM string "a,b,c" (",")

join(list)

Joins list elements with string as delimiter

LET joined: string = join FROM string "," (["a", "b"])

contains(substring)

Checks if string contains substring

LET has: bool = contains FROM string "hello" ("el")

starts_with(prefix)

Checks if string starts with prefix

LET starts: bool = starts_with FROM string "hello" ("he")

ends_with(suffix)

Checks if string ends with suffix

LET ends: bool = ends_with FROM string "hello" ("lo")

repeat(count)

Repeats string count times

LET repeated: string = repeat FROM string "ha" (3)

reverse()

Reverses the string

LET rev: string = reverse FROM string "hello" _

substr(start, length)

Gets substring from start position

LET sub: string = substr FROM string "hello" (1, 3)

pad_left(length, char)

Pads string left with char

LET padded: string = pad_left FROM string "42" (5, "0")

pad_right(length, char)

Pads string right with char

LET padded: string = pad_right FROM string "42" (5, "0")

capitalize()

Capitalizes first character

LET cap: string = capitalize FROM string "hello" _

title()

Converts string to title case

LET titled: string = title FROM string "hello world" _

Math Library (math)

sqrt()

Square root

LET root: float = sqrt FROM math 16.0 _

pow(exponent)

Power function

LET power: float = pow FROM math 2.0 (3)

abs()

Absolute value

LET abs_val: float = abs FROM math -42.5 _

floor()

Floor function

LET floor_val: int = floor FROM math 3.7 _

ceil()

Ceiling function

LET ceil_val: int = ceil FROM math 3.2 _

round(decimals)

Rounds to specified decimal places

LET rounded: float = round FROM math 3.14159 (2)

sin()

Sine function

LET sin_val: float = sin FROM math 0.0 _

cos()

Cosine function

LET cos_val: float = cos FROM math 0.0 _

tan()

Tangent function

LET tan_val: float = tan FROM math 0.0 _

pi()

Returns π constant

LET pi_val: float = pi FROM math _ _

e()

Returns e constant

LET e_val: float = e FROM math _ _

min(values...)

Returns minimum value

LET minimum: float = min FROM math (1.0, 2.0, 3.0)

max(values...)

Returns maximum value

LET maximum: float = max FROM math (1.0, 2.0, 3.0)

asin()

Arc sine function

LET asin_val: float = asin FROM math 0.5 _

acos()

Arc cosine function

LET acos_val: float = acos FROM math 0.5 _

atan()

Arc tangent function

LET atan_val: float = atan FROM math 0.5 _

log()

Natural logarithm

LET ln_val: float = log FROM math 2.718 _

log10()

Base-10 logarithm

LET log_val: float = log10 FROM math 100.0 _

exp()

Exponential function (e^x)

LET exp_val: float = exp FROM math 1.0 _

factorial()

Factorial of a number

LET fact: int = factorial FROM math 5 _

gcd(a, b)

Greatest common divisor

LET gcd_val: int = gcd FROM math (12, 18)

lcm(a, b)

Least common multiple

LET lcm_val: int = lcm FROM math (12, 18)

is_prime()

Checks if number is prime

LET prime: bool = is_prime FROM math 17 _

degrees()

Converts radians to degrees

LET deg: float = degrees FROM math 3.14159 _

radians()

Converts degrees to radians

LET rad: float = radians FROM math 180.0 _

Random Library (random)

rnd()

Random float between 0 and 1

LET r: float = rnd FROM random seed _

rnd(stop)

Random integer between 0 and stop-1

LET n: int = rnd FROM random seed (10)

rnd(start, stop)

Random integer between start and stop

LET d: int = rnd FROM random seed (1, 6)

choice(list)

Random element from list

LET item: any = choice FROM random [1, 2, 3] _

shuffle(list)

Shuffles list in place

LET shuffled: list = shuffle FROM random [1, 2, 3] _

sample(list, count)

Random sample from list

LET samples: list = sample FROM random [1,2,3,4,5] (3)

Type Library (type)

is_int(value)

Checks if value is integer

LET is_int: bool = is_int FROM type 42 _

is_float(value)

Checks if value is float

LET is_float: bool = is_float FROM type 3.14 _

is_string(value)

Checks if value is string

LET is_str: bool = is_string FROM type "hello" _

to_int(value)

Converts value to integer

LET num: int = to_int FROM type "42" _

to_float(value)

Converts value to float

LET num: float = to_float FROM type "3.14" _

to_string(value)

Converts value to string

LET str: string = to_string FROM type 42 _

is_list(value)

Checks if value is list

LET is_lst: bool = is_list FROM type [1,2,3] _

is_bool(value)

Checks if value is boolean

LET is_bool: bool = is_bool FROM type true _

get(value, type)

Gets value of specified type

LET val: any = get FROM type "42" ("int")

to_bool(value)

Converts value to boolean

LET bool_val: bool = to_bool FROM type "true" _

List Library (list)

sort([reverse])

Sorts list

LET sorted: list = sort FROM list [3,1,2] _

reverse()

Reverses list

LET rev: list = reverse FROM list [1,2,3] _

map(function)

Maps function over list

LET doubled: list = map FROM list [1,2,3] (x => x * 2)

filter(function)

Filters list by function

LET evens: list = filter FROM list [1,2,3,4] (x => x % 2 == 0)

reduce(function)

Reduces list using function

LET sum: int = reduce FROM list [1,2,3] ((x,y) => x + y)

find(element)

Finds index of element

LET idx: int = find FROM list [1,2,3] (2)

count(element)

Counts occurrences of element

LET cnt: int = count FROM list [1,2,2,3] (2)

sum()

Sums all elements

LET total: int = sum FROM list [1,2,3] _

avg()

Average of elements

LET average: float = avg FROM list [1,2,3] _

zip(other)

Combines two lists

LET zipped: list = zip FROM list [1,2] ([3,4])

enumerate()

Adds indices to elements

LET enum: list = enumerate FROM list ["a","b"] _

slice(start, end)

Gets sublist from start to end

LET sub: list = slice FROM list [1,2,3,4] (1, 3)

concat(other)

Concatenates two lists

LET combined: list = concat FROM list [1,2] ([3,4])

unique()

Gets unique elements

LET uniq: list = unique FROM list [1,2,2,3] _

Time Library (time)

now()

Current timestamp

LET timestamp: float = now FROM time _ _

format(format)

Formats time string

LET date: string = format FROM time 1704067200 ("%Y-%m-%d")

parse(string, format)

Parses time string

LET ts: float = parse FROM time "2024-01-01" ("%Y-%m-%d")

sleep(seconds)

Pauses execution

LET _ = sleep FROM time 1.5 _

File Library (file)

read()

Reads file contents

LET content: string = read FROM file "test.txt" _

write(content)

Writes to file

LET success: bool = write FROM file "test.txt"("Hello")

exists()

Checks if file exists

LET exists: bool = exists FROM file "test.txt" _

delete()

Deletes file

LET deleted: bool = delete FROM file "test.txt" _

rename(new_name)

Renames file

LET success: bool = rename FROM file "old.txt" ("new.txt")

size()

Gets file size in bytes

LET size: int = size FROM file "test.txt" _

System Library (system)

args()

Gets command line arguments

LET args: list = args FROM system _ _

env(name)

Gets environment variable

LET path: string = env FROM system "PATH" _

exec(command)

Executes system command

LET output: string = exec FROM system "echo Hello" _

exit(code)

Exits program with status code

LET _ = exit FROM system 0 _