Functions

Functions in Perun2 do not cause any side effects. Their only purpose is to return a value of certain data type. The names of functions are insensitive to case size. User cannot define new functions.

structurereturns
[function name] ( [arg1 value] ) return value
[function name] ( [arg1 value], [arg2 value] ) return value
[function name] ( [arg1 value], [arg2 value], ... ) return value

Generic

Generic functions can operate on multiple data types.

First

nameargumentsreturns
first (value collection) value
Find the first value of the collection. If the collection is empty, then an empty value is returned.

Last

nameargumentsreturns
last (value collection) value
Find the last value of the collection.

Random

nameargumentsreturns
random () number
(number) number
(string) string
(value collection) value

When called without any argument, it returns a random fractional value between 0 and 1. Function called with a floating-point argument behaves the same, but with different upper limit. If the argument is an integer, then returned is a random integer between 0 and this value minus one bound including. Function called with a string returns its random character. Finally, if the argument is a collection, then returned is a random element from it. Randomness in all cases is described either by the discrete uniform distribution or continuous uniform distribution.


Bool

Any

nameargumentsreturns
any (list) bool
Check if a collection contains at least one element.

Any Inside

nameargumentsreturns
anyinside (definition) bool
Check if current element is a directory and it contains at least one element generated by a definition.

Contains

nameargumentsreturns
contains (string, string) bool
(value collection, value)
This function can be used for two purposes: to check whether a string (arg1) contains another string (arg2) or whether a collection contains a value.

Ends With

Ends With

nameargumentsreturns
endswith (string, string) bool
Check if a string (arg1) ends with another string (arg2).

Exist

nameargumentsreturns
exist (list) bool
Check if all mentioned files and directories exist.

Exists

nameargumentsreturns
exists (string) bool
Check if a mentioned file or directory exists.

Exist Inside

nameargumentsreturns
existinside (list) bool
Check if current element is a directory and all files and directories with mentioned names exist inside it.

Exists Inside

nameargumentsreturns
existinside (string) bool
Check if current element is a directory and a file or a directory with mentioned name exist inside it.

Find Text

nameargumentsreturns
findtext (string) bool
Check if current element is a file and it contain certain text phrase (case sensitive).

Is Binary

nameargumentsreturns
isbinary (string) bool
Check if a string consists of ones are zeros.

Is Digit

nameargumentsreturns
isdigit (string) bool
Check if all characters of a string are digits.

Is Hex

nameargumentsreturns
ishex (string) bool
Check if a string contains only hexadecimal characters (0-9|a-f|A-F).

Is Letter

nameargumentsreturns
isletter (string) bool
Check if all characters of a string are letters.

Is Lower

nameargumentsreturns
islower (string) bool
Check if all letters of a string are lowercase.

Is NaN

nameargumentsreturns
isnan (number) bool
Check if a number is NaN.

Is Never

nameargumentsreturns
isnever (time) bool
Check if a time is never. Never value is a time equivalent of numerical NaN. It represents wrong or missing moments in time.

Is Number

nameargumentsreturns
isnumber (string) bool
Check if a string could be converted into a valid number. Potential suffixes are not taken into account. Function returns false if a string contains any character that is not a digit, dot nor minus sign.

Is Upper

nameargumentsreturns
isupper (string) bool
Check if all letters of a string are uppercase.

Starts With

nameargumentsreturns
startswith (string, string) bool

Check if a string (arg1) starts with another string (arg2).


Number

Absolute

nameargumentsreturns
absolute (number) number
Absolute value of a number.

Ceil

nameargumentsreturns
ceil (number) number
Return the smallest integer that is greater than or equal to a number.

Count

nameargumentsreturns
count (list) number
Count elements in a collection.

Count Inside

nameargumentsreturns
countinside (definition) number
Count elements defined by a definition inside a current element (provided it is a directory).

Floor

nameargumentsreturns
floor (number) number
Return the greatest integer that is less than or equal to a number.

From Binary

nameargumentsreturns
frombinary (string) number
Convert a string consisting of zeros and ones into a number. Return NaN if the string contains any other character. Fractional values are not supported.

From Hex

nameargumentsreturns
fromhex (string) number
Convert a string with a hexadecimal number into a normal decimal number. Return NaN if the string contains any not allowed character. Fractional values are not supported.

Length

nameargumentsreturns
length (string) number
Get length of a string.

Number

nameargumentsreturns
number (string) number
Convert a string into a number. Return NaN in case of a failure. Suffixes are not taken into account and they cause a failure.

Power

nameargumentsreturns
power (number, number) number
Return a number (arg1) to the power of another number (arg2).

Resemblance

nameargumentsreturns
resemblance (string, string) number
This function returns a fractional value between 0 and 1. It performs the resemblance algorithm on its arguments. Returns zero if arguments do not share any common character. Returns one if a string (arg1) is already a substring of the other string (arg2) while following the rules of the Resembles operator for character equality.

Round

nameargumentsreturns
round (number) number
Round a number to the nearest integer.

Shift Month

nameargumentsreturns
shiftmonth (time, number)number
(number, number)
Take a month as a number (arg1) and shift it by another number (arg2). Function can take a negative second argument and they all are treated as integers. Numbers can wrap around. For example, value 11 (November) shifted by 4 becomes 3 (March).

Shift Week Day

nameargumentsreturns
shiftweekday (time, number)number
(number, number)
Take a day of the week as a number (arg1) and shift it by another number (arg2). As in Shift Month, numbers are integers, can wrap around and be negative. For example, value 1 (Monday) shifted by -2 becomes 6 (Saturday).

Sign

nameargumentsreturns
sign (number) number
If a number is negative, return -1. If a number is 0, return 0. Otherwise return 1.

Size

nameargumentsreturns
size (list) number
Calculate the total size of all files and directories.

Sqrt

nameargumentsreturns
sqrt (number) number
Square root of a number.

Truncate

nameargumentsreturns
truncate (number) number

Cut off fractional part from a number.


Aggregate

Aggregate functions are a special kind of numeric functions. They all return a number and can take any amount of arguments (at least one). Arguments are restricted to only two data types: number and numeric list. Any NaN argument make the result NaN.
average max min
median sum

Time

Christmas

nameargumentsreturns
christmas (number) time
Return 24 December of certain year.

Clock

nameargumentsreturns
clock (number, number) time
(number, number, number)
Create a new clock. Arguments are the same as in the declaration of a clock constant. See data types.

Date

nameargumentsreturns
date (number, number, number) time
Create a new date. Arguments are: day, month, year.

Easter

nameargumentsreturns
easter (number) time
Return the day of Easter of certain year.

New Year

nameargumentsreturns
newyear (number) time
Return the moment of certain New Year. Hours, minutes and seconds are included and set to 0.

Time

nameargumentsreturns
time (number, number) time
(number, number, number)
(number, number, number, number, number)
(number, number, number, number, number, number)

Create a new time. Arguments are the same as in the declaration of a time constant. See data types.


Period

Duration

nameargumentsreturns
duration (list) period

Calculate the total duration of all files.


String

After

nameargumentsreturns
after (string, string) string
Get the part of the base string (arg1) that stays after the first occurence of the string (arg2) inside the base string (arg1).

After Digits

nameargumentsreturns
afterdigits (string) string
Get the part of the string that stays after the first consecutive series of digits.

After Letters

nameargumentsreturns
afterletters (string) string
Get the part of the string that stays after the first consecutive series of letters.

Before

nameargumentsreturns
before (string, string) string
Get the part of the base string (arg1) that stays before the first occurence of the string (arg2) inside the base string (arg1).

Before Digits

nameargumentsreturns
beforedigits (string) string
Get the part of the string that stays before the first existing digit.

Before Letters

nameargumentsreturns
beforeletters (string) string
Get the part of the string that stays before the first existing letter.

Binary

nameargumentsreturns
binary (number) string
Represent a number in the binary form. Fractional values are not supported.

Capitalize

nameargumentsreturns
capitalize (string) string
Make all words start with a capital letter. Remaining letters are transformed into lowercase.

Concatenate

nameargumentsreturns
concatenate (value, ...) string
Merge multiple elements into one string.

Digits

nameargumentsreturns
digits (string) string
Take all digits from a string.

Fill

nameargumentsreturns
fill (string, number) string
If a string (arg1) is shorter than a desired length (arg2), then zeros are added at the beginning of the string to fill the difference. Use this function to convert integers into strings with constant length. For example: 001, 002, ... 021, 022.

Hex

nameargumentsreturns
hex (number) string
Represent a number in the hexadecimal form with lowercase letters. Fractional values are not supported.

Join

nameargumentsreturns
join (list, string) string
Combine all elements of a list (arg1) into one string using a separator (arg2).

Left

nameargumentsreturns
left (string, number) string
Take certain amount of characters (arg2) from a string (arg1). This is done starting from left.

Letters

nameargumentsreturns
letters (string) string
Take all letters from a string.

Lower

nameargumentsreturns
lower (string) string
Change all letters in a string to lowercase.

Month Name

nameargumentsreturns
monthname (number) string
Get English name of certain month. January is 1, December is 12.

Parent

nameargumentsreturns
parent (string) string
Get absolute path to the location certain element directly is in.

Path

nameargumentsreturns
path (string) string
If the function is called with one string argument, it returns absolute path to certain element.

Path

nameargumentsreturns
path (string, string...) string
If the function contains at least 2 string arguments, it combines multiple filesystem path segments into one path. If certain element is an absolute path, it becomes a new base for the path and all previous arguments are ignored. An invalid or empty argument turns the final result into empty string.

Raw

nameargumentsreturns
raw (string) string
Change all letters to their raw latin form. All diacritical and combining marks are removed from the characters. In addition, turn every ß to ss, every æ to ae and every œ to oe (and their uppercase variants). Letter case is preserved.

Repeat

nameargumentsreturns
repeat (string, number) string
Repeat a string (arg1) certain amount of times (arg2).

Replace

nameargumentsreturns
replace (string, string, string) string
Replace every occurence of a string (arg2) inside a string (arg1) with a new value (arg3).

Reverse

nameargumentsreturns
reverse (string) string
Reverse a string.
nameargumentsreturns
right (string, number) string
Take certain amount of characters (arg2) from a string (arg1). This is done starting from right.

Roman

nameargumentsreturns
roman (number) string
Express a number as roman literals. Works only for numbers smaller than 5 million. Large numbers use the vinculum system. Fractions are also expressed, but the smallest unit is the ounce (one twelfth).

Size

nameargumentsreturns
size (list) string
Count total size of all mentioned files and directories.

String

nameargumentsreturns
string (bool) string
(number)
(time)
(period)
Convert certain value into a string. This function seems to be pointless as Perun2 performs automatic data type casts. However, there are still several use cases for it. For example, it is necessary to apply this function in order to differentiate string concatenation from arithmetic summation.

Substring

nameargumentsreturns
substring (string, number) string
(string, number, number)
This functions can be called in two ways: with two or three arguments. Two-argument subtring returns a string (arg1) excluding certain amount of characters (arg2) from the beginning. On the other hand, the same function called with three arguments returns certain amount of characters (arg3) from a string (arg1) starting at position (arg2). Like everywhere else, indexing is zero-based.

Trim

nameargumentsreturns
trim (string) string
Remove whitespace characters from the beginning and end of the string.

Upper

nameargumentsreturns
upper (string) string
Change all letters in a string to uppercase.

Week Day

nameargumentsreturns
weekday (number) string

Get English name of certain day of the week. Monday is 1, Sunday is 7.


List

Characters

nameargumentsreturns
characters (string) list
Transform a string into a list of characters.

Numbers

nameargumentsreturns
numbers (string) numeric list
Find all integers inside a string.

Split

nameargumentsreturns
split (string, string) list
Divide a string (arg1) by a separator (arg2).

Words

nameargumentsreturns
words (string) list

Divide a string into words. Every word is a consecutive series of letters.