builtin

Built-in functions and variables.

General

print

Prints values to stdout or a file. It prints to stdout if file argument is 1, stderr if 2, or a file if string.

(def (print ..args . sep " " end "\n" file 1 mode 0664))
(type (print [any] . string string (or number string) number) nil)

partial

Applies a function to arguments partially and creates a new function.

(def (partial func ..args . ..kwargs))
(type (partial function [any] . dictionary) function)

toString

Converts a value into its string representation. This function doesn’t modify strings.

(def (toString arg))
(type (toString any) string)

dump

Converts a value into its string representation. It is similar to toString function but converts strings into quoted ones.

(def (dump arg))
(type (dump any) string)

pure

Treats an impure function call as a pure function call.

(def (pure arg))
(type (pure any) any)

Conditionals

if

Takes pairs of a condition and an expression and a fallback expression, and returns an expression corresponding with the first condition evaluated as true or the last expression if no conditions are met.

(def (if ..args))
(type (if [any]) any)

not

Negates an argument.

(def (not arg))
(type (not boolean) boolean)

and

Returns true if all arguments are true, or false otherwise.

(def (and ..args))
(type (and [boolean]) boolean)

or

Returns true if at least one argument is true, or false otherwise.

(def (or ..args))
(type (or [boolean]) boolean)

Arithmetic

+, -, *, /

Adds, subtracts, multiplies, or devides numbers.

(def (+ ..nums))
(type (+ [number]) number)

(def (- initial ..nums))
(type (- number [number]) number)

(def (* ..nums))
(type (* [number]) number)

(def (/ initial ..nums))
(type (/ number [number]) number)

//

Calculates a floor division.

(def (// initial ..nums))
(type (// number [number]) number)

**

Calculates a power.

(def (** first second))
(type (** number number) number)

mod

Calculates a modulus.

(def (mod first second))
(type (mod number number) number)

max, min

Returns a maximum or minimum of arguments.

(def (max ..args))
(type (max [number]) number)

Comparison

=

Returns true if all arguments are equal, or false otherwise. Values of any types except function can be compared with this function.

(def (= ..args))
(type (= [any]) boolean)

<, <=, >, >=

Compares arguments and returns true if they are ordered properly, or false otherwise. Their semantics are almost the same as mathematics’s but they can compare not only number values but also list and string ones.

(def (< ..args))
(type (< [(or list number string)]) boolean)

ordered?

Returns true if an argument can be compared by ordering functions like <, or false otherwise.

(def (ordered? arg))
(type (ordered? any) boolean)

Collection

@

Gets an element in a collection. When multiple keys are passed, the function returns an element in nested collections.

(def (@ collection key ..keys))
(type (@ (or dictionary list string) any [any]) any)

insert

Inserts elements into a collection.

(def (insert collection ..keyValuePairs))
(type (insert (or dictionary list string) [any])
  (or dictionary list string))

delete

Deletes an entry from a collection.

(def (delete collection elem))
(type (delete (or dictionary list string) any)
  (or dictionary list string))

include

Checks if a value is included in a collection.

(def (include collection elem))
(type (include (or dictionary list string) any) boolean)

merge

Merges collections into one.

(def (merge collection ..collections))
(type (merge (or dictionary list string) [(or dictionary list string)])
  (or dictionary list string))

size

Returns a size of a collection.

(def (size collection))
(type (size (or dictionary list string)) number)

toList

Converts a collection into its list representation.

(def (toList collection))
(type (toList (or dictionary list string)) list)

List manipulation

first

Gets a first element in a list.

(def (first list))
(type (first list) any)

rest

Removes a first element from a list and returns the rest.

(def (rest list))
(type (rest list) list)

map

Applies a function to each element in a list.

(def (map func list))
(type (map function list) list)

reduce

Accumulates values with a function which takes 2 arguments of an acumulator value and an element in a list.

(def (reduce func list))
(type (reduce function list) any)

filter

Returns a list of elements which satisfy a condition represented by func argument. The func argument must be a function which takes an argument and returns boolean.

(def (filter func list))
(type (filter function list) list)

sort

Sorts elements in a list.

(def (sort list . less <))
(type (sort list . function) list)

zip

Returns a list of lists each of which contains elements of the same index in original lists.

(def (zip ..lists))
(type (zip [list]) [list])

slice

Slices a list. Indices are inclusive.

(def (slice list))
(type (slice list (start 1) (end nil)) list)

index

Finds an element in a list and returns its index.

(def (index list elem))
(type (index list any) number)

Typing

typeOf

Returns a type of an argument.

(def (typeOf arg))
(type (typeOf any) string)

boolean?, dictionary?, function?, list?, nil?, number?, string?

Checks if an argument is the type.

(def (boolean? arg))
(type (boolean? any) boolean)

Error handling

catch

Catches an error thrown from an expression.

(def (catch arg))
(type (catch any) (or {"name" string "message" string} nil))

Parallelism and concurrency

par

Evaluates arguments parallelly and returns the last one.

(def (par ..args))
(type (par [any]) any)

seq

Evaluates arguments sequentially and returns the last one.

(def (seq ..args))
(type (seq [any]) any)

seq!

Evaluates impure function calls sequentially and returns the last one. This function itself is also impure.

(def (seq! ..args))
(type (seq! [any]) any)

rally

Sorts arguments by time when each of them becomes available.

(def (rally ..args))
(type (rally [any]) [any])