lisp-lists
lisp-lists.tolk Tolk standard library file
Definitions
lisp_list<T>.isEmpty
@pure
fun lisp_list<T>.isEmpty(self): boollisp_list<T>.prependHead
@pure
fun lisp_list<T>.prependHead(mutate self, value: T): voidInserts an element an the front.
Before: [a b c].
After: [new a b c].
lisp_list<T>.popHead
@pure
fun lisp_list<T>.popHead(mutate self): TPops 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.
lisp_list<T>.getHead
@pure
fun lisp_list<T>.getHead(self): TReturns an element from the front: a for [a b c].
Throws an exceptions if a list is empty.
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.
lisp_list<T>.calculateSize
@pure
fun lisp_list<T>.calculateSize(self): intCalculates 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 codelisp_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].
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].
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> [];lisp_list<T>.packToBuilder
fun lisp_list<T>.packToBuilder(self, mutate b: builder): voidlisp_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"
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]]]).
Last updated on