Next: , Previous: , Up: stacks   [Index]


36.8 Converting stacks to other objects

The following syntactic bindings are exported by the library (vicare containers stacks). The syntactic bindings whose name is prefixed with $ are unsafe operations: they do not validate their arguments before accessing them.

Function: stack->list stack
Function: $stack->list stack
Function: list->stack list
Function: $list->stack list

Convert to and from a stack and a proper list. Objects from the list are pushed on the stack left–to–right from the bottom side.

(define D
  (list->stack '(0 1 2)))

(stack-top   D)        ⇒ 0
(stack->list D)        ⇒ (0 1 2)
Function: stack->vector stack
Function: $stack->vector stack
Function: vector->stack vector
Function: $vector->stack vector

Convert to and from a stack and a vector. Objects from the vector are pushed on the stack left–to–right from the bottom side.

(define D
  (vector->stack '#(0 1 2)))

(stack-top     D)       ⇒ 0
(stack->vector D)       ⇒ #(0 1 2)