http://zorba.io/modules/stack

View as XML or JSON.

Implementation of stack for items, using dynamic collections.

Entries in the stack must be structured items - that is, either JSON Objects or Arrays, or XML Nodes.

Function Summary

copy ($destName as xs:QName, $sourceName as xs:QName) as empty-sequence()

Copy all items from source stack to a destination stack.

create ($name as xs:QName) as empty-sequence()

Create a stack with this name.

empty ($name as xs:QName) as xs:boolean

Checks if a stack exists and is empty.

pop ($name as xs:QName) as structured-item()?

Return the top item in the stack, and remove it.

push ($name as xs:QName, $value as structured-item()) as empty-sequence()

Add a new item to the stack; the stack will contain a copy of the given item.

size ($name as xs:QName) as xs:integer

Count of items in the stack.

top ($name as xs:QName) as structured-item()?

Return the top item in the stack, without removing it.

Functions

copy#2

declare  %ann:sequential function stack:copy($destName as xs:QName, $sourceName as xs:QName) as empty-sequence()
Copy all items from source stack to a destination stack.

If destination stack does not exist, it is created first.

If destination stack is not empty, the items are appended on top.

Parameters

destName as xs:QName
name of the destination stack.
sourceName as xs:QName
name of the source stack.

Returns

empty-sequence()
an empty sequence.

create#1

declare  %ann:sequential function stack:create($name as xs:QName) as empty-sequence()
Create a stack with this name. If stack exists, an error is raised.

Parameters

name as xs:QName
name of the new stack.

Returns

empty-sequence()
an empty sequence.

empty#1

declare  function stack:empty($name as xs:QName) as xs:boolean
Checks if a stack exists and is empty.

Parameters

name as xs:QName
name of the stack.

Returns

xs:boolean
true if the stack is empty or does not exist.

pop#1

declare  %ann:sequential function stack:pop($name as xs:QName) as structured-item()?
Return the top item in the stack, and remove it.

Parameters

name as xs:QName
name of the stack.

Returns

structured-item()?
the top item, or empty sequence if stack is empty.

push#2

declare  %ann:sequential function stack:push($name as xs:QName, $value as structured-item()) as empty-sequence()
Add a new item to the stack; the stack will contain a copy of the given item.

Parameters

name as xs:QName
name of the stack.
value as structured-item()
the item to be added.

Returns

empty-sequence()
an empty sequence.

size#1

declare  function stack:size($name as xs:QName) as xs:integer
Count of items in the stack.

Parameters

name as xs:QName
name of the stack.

Returns

xs:integer
the amount of items.

top#1

declare  function stack:top($name as xs:QName) as structured-item()?
Return the top item in the stack, without removing it.

Parameters

name as xs:QName
name of the stack.

Returns

structured-item()?
the top item, or empty sequence if stack is empty.