Skip to content

Module std

Lindon Aliu edited this page Jan 29, 2024 · 1 revision

The std module in EK provides a set of functions that are useful for writing programs in EK. It is not automatically imported and must be imported explicitly using the import keyword.

You may alternatively import another standard library, such as rpn which provides the same functionality as std but with a different syntax.

Types

int

An integer value of arbitrary size.

bool

A boolean value, either true or false.

string

A string value, such as "Hello, world!".

any

Any value.

void

An atom indicating that there is no necessary value.

float

A 64-bit floating-point value.

Functions

print

fn print (value: any): void

Prints the value to the standard output, followed by a newline.

eprint

fn eprint (value: any): void

Prints the value to the standard error, followed by a newline.

readLine

fn readLine: string

Reads a line from the standard input.

exit

fn exit (code: int): void

Exits the program with the given exit code (between 0 and 255).

assert

fn assert (condition: bool) message (str: string): void

Asserts that the given condition is true. If it is not, the program will exit with an exit code of 1 and print the given message to the standard error.

panic

fn panic (message: string): void

Exits the program with an exit code of 1 and prints the given message to the standard error.

clamp

fn clamp (value: int) min (min: int) max (max: int): int

Clamps the given value between the given minimum and maximum values.

min / max

fn (a: int) min (b: int): int
fn (a: int) max (b: int): int

Returns the minimum/maximum of the two given values.

toString

fn (value: any) toString: string

Returns a string representation of the given value.

if

fn if (condition: bool) then (lazy then: any) else (lazy otherwise: any): any

Returns the then value if the condition is true, otherwise returns the otherwise value.

Operators

+ / - / * / /

fn (a: int) + (b: int) precedence 6: int
fn (a: int) - (b: int) precedence 6: int
fn (a: int) * (b: int) precedence 7: int
fn (a: int) / (b: int) precedence 7: int

Returns the sum/difference/product/quotient of the two given values.

== / !=

fn (a: any) == (b: any) precedence 4: bool
fn (a: any) != (b: any) precedence 4: bool

Returns true if the two given values are equal/not equal.

< / <= / > / >=

fn (a: int) < (b: int) precedence 4: bool
fn (a: int) <= (b: int) precedence 4: bool
fn (a: int) > (b: int) precedence 4: bool
fn (a: int) >= (b: int) precedence 4: bool

Returns true if the first value is less than/equal to/greater than/equal to the second value.

&& / ||

fn (a: bool) && (lazy b: bool) precedence 3: bool
fn (a: bool) || (lazy b: bool) precedence 2: bool

Returns the logical AND/OR of the two given booleans. The second value is only evaluated if necessary.

not

fn not (value: bool) precedence 9: bool

Returns the logical NOT of the given boolean.

>>

fn (a: any) >> (b: t) precedence 1: t

Returns the second value after evaluating the first value.

$

fn (f: a -> b) $ (value: a) precedence 0: b

Returns the result of applying the function f to the value value.

.

fn (f: b -> c) . (g: a -> b) precedence 9: a -> c

Returns the composition of the two given functions.

Clone this wiki locally