Topics






Builtin functions



Builtin functions are defined by the interpreter. A list of built-in functions is given below

FunctionSyntaxDescription
printprint(toprint1,...)Prints all given arguments
printlnprintln(toprint1,...)Same as print but also prints newline after printing all arguments
formatformat(formatstr,arg1, ...)Formats the given string and returns a new string. It replaces all '%' characters in formatstr with given arguments.
printfprintf(formatstr,arg1, ...)Prints the formatted string instead of returning it.
reversereverse(s)Returns the reverse of string or reverses a list inplace and returns nil
splitsplit(str,delim)Returns a list of strings by splitting the passed string at specified delimeter
shuffleshuffle(x)Shuffles a list
getenvgetenv(s)Returns the value of an environment variable. Returns nil on failure
lenlen(s)Returns the length of string,list or dictionary
inputinput(prompt = "")Takes string input from user and returns it. The prompt is optional and empty string by default
findfind(x,s)Finds and returns the starting index of string x in s. Returns nil if no occurrence is found
replacereplace(x,y,s)Replaces all occurrences of x with y in string s
replace_oncereplace(x,y,s)Replaces only first occurrence
strstr(x)Converts x to string and returns it. Throws error if conversion is not possible
intint(x)Converts x to integer and returns it. The result can be int32 or int64. Throws error if conversion is not possible
int32int32(x)Converts x to integer 32 bit and returns it. The result is always int32. Throws error if conversion is not possible
int64int64(x)Converts x to integer 64 bit and returns it. The result is always int64. Throws error if conversion is not possible
floatfloat(x)Converts x to float and returns it. Throws error if conversion is not possible
tonumerictonumeric(s)Converts string to a numeric type(float or integer) if possible otherwise throws an error
isnumericisnumeric(s)Returns true if a string can be convert to numeric type
openopen(filename, mode)Opens a file in specified mode and returns a file object. Throws error if file cannot be opened
readread(file)Reads and returns file data as string.
closeclose(file)Closes the file
readlinesreadlines(file)Returns a list of strings containing lines read from the file
writelineswritelines(lines, file)Writes a list of lines to the file
writewrite(data, file)Writes a string to the file
freadfread(n, file)Reads n bytes from the file
fwritefwrite(bytes, file)Writes given bytes to the file
fseekfseek(file, n, whence)Seeks the filestream n bytes relative to whence
sleepsleep(x)Sleeps for x milliseconds
substrsubstr(x,y,str)Returns substring of str starting from index x to index y
cloneclone(x)Makes a deep copy of a list or dictionary
systemsystem(s)Executes a system command and returns the exit code
powpow(x,y)Returns x raised to the power y
exitexit(retcode = 0)Exits program returning retcode.