std

Contains common functions

Constants

ARGS : string Desktop = command-line arguments

Functions

arrayCombine(keys, values) - creates map by combining two arrays

arrayKeyExists(key, map) - checks existing key in map. 1 - exists, 0 - no

arrayKeys(map) - returns array of map keys

arrayValues(map) - returns array of map values

charAt(input, index) - returns char code in position index of string input

clearConsole() Android - clears console

echo(arg...) - prints values to console, separate them by space and puts newline at the end. Takes variable number of arguments

Example

echo(1, "abc") // prints "1 abc" to console
echo(1, 2, 3, 4, 5, "a", "b") // prints "1 2 3 4 5 a b"

indexOf(input, what, index = 0) - finds first occurrence of what in string input, starting at position index

join(array, delimiter = "", prefix = "", suffix = "") - join array to string with delimiter, prefix and suffix

lastIndexOf(input, what, index = 0) - finds last occurrence of what in string input, starting at position index

length(x) - returns length of string, array/map size or number of function arguments

newarray(size...) - creates array with size.

newarray(x) - creates 1D array, newarray(x,y) - creates 2D array

Example

newarray(4) // [0, 0, 0, 0]
newarray(2, 3) // [[0, 0, 0], [0, 0, 0]]

parseInt(str, radix) - parses string into integer in the radix

parseLong(str, radix) - parses string into long in the radix

rand(from = 0, to = ..) - returns pseudo-random number.

rand() - returns float number from 0 to 1

rand(max) - returns random number from 0 to max

rand(from, to) - return random number from from to to

range(from = 0, to, step = 1) - creates lazy array by number range.

range(to) - creates range from 0 to to (exclusive) with step 1

range(from, to) - creates range from from to to (exclusive) with step 1

range(from, to, step) - creates range from from to to (exclusive) with step step

Example

print range(3) // [0, 1, 2]
r = range(-5, 0) // [-5, -4, -3, -2, -1]
print r[0] // -5
print r[2] // -3
for x : range(20, 9, -5) {
 println x
} // 20 15 10

readln(x) Desktop - reads a line from console

replace(str, target, replacement) - replaces all occurrences of string target with string replacement

replaceAll(str, regex, replacement) - replaces all occurrences of regular expression regex with string replacement

replaceFirst(str, regex, replacement) - replaces first occurrence of regular expression regex with string replacement

sleep(time) - causes current thread to sleep for time milliseconds

sort(array, comparator = ..) - sorts array by natural order or by comparator function

split(str, regex, limit = 0) - splits string str with regular expression regex into array. limit parameter affects the length of resulting array

Example

split("a5b5c5d5e", "5") // ["a", "b", "c", "d", "e"]
split("a5b5c5d5e", "5", 3) // ["a", "b", "c5d5e"]

sprintf(format, args...) - formats string by arguments

substring(str, startIndex, endIndex = ..) - returns string from startIndex to endIndex or to end of string if endIndex is not set

Example

substring("abcde", 1) // bcde
substring("abcde", 2, 4) // cd

sync(callback) - calls an asynchronous function synchronously

Example

result = sync(def(ret) {
 http(url, def(t) = ret(t))
})

thread(func, args...) - creates new thread with parameters if passed

Example

thread(def() {
 print "New Thread"
})
thread(::newthread, 10)
thread("newthread", 20)
def newthread(x) {
 print "New Thread. x = " + x
}

time() - returns current time in milliseconds from 01.01.1970

toChar(code) - converts char code to string

Example

toChar(48) // "0"

toHexString(number) - converts number into hex string

toLowerCase(str) - converts all symbols to lower case

toUpperCase(str) - converts all symbols to upper case

trim(str) - removes any leading and trailing whitespaces in string

try(unsafeFunction, catchFunction = def(type, message) = -1) - suppress any error in unsafeFunction and returns the result of the catchFunction if any error occurs

Example

try(def() = "success") // success
try(def() = try + 2) // -1
try(def() = try(), def(type, message) = sprintf("Error handled:\ntype: %s\nmessage: %s", type, message))

results matching ""

    No results matching ""