Go to the first, previous, next, last section, table of contents.


The Stack Data Type

The stack data type provides a simple LIFO stack. There are two implementations of a stack in Elib, one using macros and one using functions. The names of the functions/macros in the two implementations are the same, but the efficiency of using one or the other vary greatly under different circumstances.

The implementation using macros should be used when you want to byte-compile your own elisp program. This will be most efficient since byte-compiling an elisp function using macros has the same effect as using inline code in C.

To use the stack data type, put the line

(require 'stack-f)

in your own elisp source file if you want to use the implementation using functions or

(require 'stack-m)

if you want to use the implementation using macros. This is the only difference between them, so it is easy to switch between them during debugging.

The following functions are provided by the stack:

(stack-create)
Create a new empty stack.
(stack-p stack)
Return t if stack is a stack, otherwise return nil.
(stack-push stack element)
Push element onto stack.
(stack-pop stack)
Remove the topmost element from stack and return it. If stack is empty, return nil.
(stack-empty stack)
Return t if stack is empty, otherwise return nil.
(stack-top stack)
Return the top element of stack, but don't remove it from the stack. Return nil if stack is empty.
(stack-nth stack n)
Return the nth element of stack where the top stack element has number 0. If stack is not that long, return nil. The element is not removed from the stack.
(stack-all stack)
Return a list of all entries in stack with the topmost element first.
(stack-copy stack)
Return a copy of stack. All entries in stack are also copied.
(stack-length stack)
Return the number of elements in stack.
(stack-clear stack)
Remove all elements from stack.


Go to the first, previous, next, last section, table of contents.