Acton
Tolk standard library

lisp-lists

lisp-lists.tolk Tolk standard library file

Definitions

lisp_list<T>.isEmpty

@pure
fun lisp_list<T>.isEmpty(self): bool
Source code

lisp_list<T>.prependHead

@pure
fun lisp_list<T>.prependHead(mutate self, value: T): void

Inserts an element an the front. Before: [a b c]. After: [new a b c].

Source code

lisp_list<T>.popHead

@pure
fun lisp_list<T>.popHead(mutate self): T

Pops an element from the front and returns it. Before: [a b c]. After: [b c], returns a. Throws an exceptions if a list is empty.

Source code

lisp_list<T>.getHead

@pure
fun lisp_list<T>.getHead(self): T

Returns an element from the front: a for [a b c]. Throws an exceptions if a list is empty.

Source code

lisp_list<T>.getTail

@pure
fun lisp_list<T>.getTail(self): lisp_list<T>

Returns all but the frontmost element: [b c] for [a b c]. Throws an exceptions if a list is empty.

Source code

lisp_list<T>.calculateSize

@pure
fun lisp_list<T>.calculateSize(self): int

Calculates the size of a list by looping all the elements (there is no other way to do it). The longer the list — the more gas consumption (O(N) complexity).

Source code

lisp_list<T>.calculateReversed

@pure
fun lisp_list<T>.calculateReversed(self): lisp_list<T>

Returns the list with elements in reversed order. Given [a b c] returns [c b a].

Source code

lisp_list<T>.calculateConcatenation

@pure
fun lisp_list<T>.calculateConcatenation(self, other: lisp_list<T>): lisp_list<T>

Returns the concatenation of two lists. Given [a b] and [c d], returns [a b c d].

Source code

createEmptyList

@pure
@deprecated("use `[]` instead of `createEmptyList`")
fun createEmptyList<T>(): lisp_list<T>

Creates a lisp_list<T> with zero elements. Deprecated. Use [] syntax instead:

// old way, deprecated:
var list = createEmptyList<int>();

// new way, preferred:
var t = lisp_list<int> [];
Source code

lisp_list<T>.packToBuilder

fun lisp_list<T>.packToBuilder(self, mutate b: builder): void

lisp_list<T> can be serialized if T is serializable. It's encoded as reversed snake refs: A list [1 2 3] (on a stack: [1 [2 [3 null]]]) is "3.ref(2.ref(1.ref(empty cell)))". An empty list [] (on a stack: null) is "empty cell"

Source code

lisp_list<T>.unpackFromSlice

fun lisp_list<T>.unpackFromSlice(mutate s: slice): lisp_list<T>

Unserialize lisp_list<T> from snake refs: From "3.ref(2.ref(1.ref(empty cell)))" get a list [1 2 3] (on a stack: [1 [2 [3 null]]]).

Source code

Last updated on

On this page