Pyro

A dynamically-typed, garbage-collected scripting language.

Version 0.16.14

Stacks



A stack object, stack, is a LIFO (last-in-first-out) container type.

$stack() -> stack

Creates a new stack.

Iterating

Stacks are iterable, e.g.

var stack = $stack();
stack:push("foo");
stack:push("bar");

for item in stack {
    echo item;
}

Containment

You can check if a stack contains an item using the in operator, e.g.

var stack = $stack();
stack:push("foo");
stack:push("bar");

assert "foo" in stack;

This is equivalent to calling the stack's :contains() method.

Methods

:clear()

Removes all items from the stack.

:contains(value: any) -> bool

Returns true if the stack contains an item equal to value, otherwise false.

:count() -> i64

Returns the number of items in the stack.

:is_empty() -> bool

Returns true if the stack is empty.

:iter() -> iter

Returns an iter object wrapping the stack.

:peek() -> any

Returns the item on top of the stack without removing it. Returns an err if the stack is empty.

:pop() -> any

Removes and returns the item on top of the stack. Returns an err if the stack is empty.

:push(item: any)

Pushes an item onto the stack.

:values() -> iter

Returns an iterator over the stack's values.