Skip to content

Standard Library

FirePlank edited this page Mar 6, 2024 · 3 revisions

Welcome to the documentation for the standard library of ShortLang. This concise yet powerful language comes equipped with a range of functions to enhance your coding experience. Below are all the built-in functions you might need.

Functions

$A

Prints to stdout with a newline at the end.

$$A

Prints to stdout without a newline at the end.

abs(A)

Returns the absolute value of A.

args()

Returns the command-line arguments given to the program.

ceil(A)

Rounds up to the next integer.

chr(A)

Returns the ascii value of A.

env [3 overloads]

  • env()

    Gets all the environment variables as an array of key-value pairs.
  • env(A)

    Gets the value of the specified environment variable.
  • env(A, B)

    Sets the value of the specified environment variable.

exit [2 overloads]

  • exit()

    Terminates the program with exit code 0.
  • exit(A)

    Terminates the program with the specified exit code.

fib(A)

Returns the nth fibonacci number.

floor(A)

Rounds down to the previous integer.

flt(A)

Tries to convert A to a float, returns an error if it fails.

gcd(A, B)

Returns the greatest common divisor of A and B.

inp [2 overloads]

  • inp()

    Read a line from stdin.
  • inp(A)

    Read a line from stdin, with a prompt.

int(A)

Tries to convert A to an integer, returns an error if it fails.

isprime(A)

Checks whether A is a prime.

lcm(A, B)

Returns the least common multiple of A and B.

len(A)

Returns the length of A.

lprime(A)

Finds the previous prime number.

nprime(A)

Finds the next prime number.

open(A)

Opens a file.

ord(A)

Returns the character associated with the ascii value of A.

prime(A)

Returns the nth prime number.

rnd [3 overloads]

  • rnd()

    Returns a random number.
  • rnd(A)

    Returns a random number between 0 and A.
  • rnd(A, B)

    Returns a random number between A and B.

rng [2 overloads]

  • rng(A)

    Returns an array with values from 0 to A.
  • rng(A, B)

    Returns an array with values from A to B.

root(A, B)

Calculates the nth root of A.

round [2 overloads]

  • round(A)

    Rounds to the nearest integer.
  • round(A, B)

    Rounds to the specified precision.

run(A)

Executes a shell command.

sqrt(A)

Calculates the square root of A.

str(A)

Converts a value to a string.

type(A)

Returns the type of A.


Methods

array

  • clear()

    Removes all the elements from the array or string.
  • join(A)

    Flattens an array a single value string, placing a given separator between each element.
  • max()

    Finds the largest element in the array.
  • min()

    Finds the smallest element in the array.
  • mul()

    Calculates the product of all the values of the array.
  • pop()

    Pops the last element and returns it.
  • push(A)

    Pushes a value to the end of the array or string.
  • sort()

    Sorts the array.
  • sub()

    Subtracts all the elements from the first one.
  • sum()

    Calculates the sum of all the values inside an array.
  • type()

    Returns the value type.

bool

  • type()

    Returns the value type.

file

  • a(A)

    Appends the contents to the file.
  • r()

    Reads everything from the file.
  • type()

    Returns the value type.
  • w(A)

    Writes the contents to the file.

float

  • cos()

    Computes the cosine.
  • cot()

    Computes the cotangent.
  • csc()

    Computes the cosecant.
  • sec()

    Computes the secant.
  • sin()

    Computes the sine.
  • tan()

    Computes the tangent.
  • type()

    Returns the value type.

int

  • cos()

    Computes the cosine.
  • cot()

    Computes the cotangent.
  • csc()

    Computes the cosecant.
  • sec()

    Computes the secant.
  • sin()

    Computes the sine.
  • tan()

    Computes the tangent.
  • type()

    Returns the value type.

nil

  • type()

    Returns the value type.

str

  • clear()

    Removes all the elements from the array or string.
  • pop()

    Pops the last element and returns it.
  • push(A)

    Pushes a value to the end of the array or string.
  • split(A)

    Returns an array containing the substrings of a string, separated by specified character.
  • type()

    Returns the value type.