libraries/stacks.nv

rules

> Variable
result
Value
Variable
Value
> Variable
lua
local result = popFact('result')
       f(Variable, result.tokens)
> Variable Name
result
Value
Variable Name
Value
> Var1 and Var2
result
Value
Var1
Value
Var2
Value
get element at Index in Stack
lua
local index = #stacks[Stack] + 1 - Index
       f('result', stacks[Stack][index].tokens)
get length of Stack stack
lua
local length = stacks[Stack] and #stacks[Stack] or 0
       f('result', {length})
move Stack to Destination
lua
stacks[Destination] = nil
       stacks[Destination] = stacks[Stack]
       stacks[Stack] = nil
  
ruby
$stacks.delete destination
        $stacks[destination] = $stacks[stack]
        $stacks.delete stack
put Value on Stack Amount times
ruby
amount.to_i.times do f stack, [value] end
reverse Stack to Destination
lua
while stacks[Stack] do
         local fact = popFact(Stack)
         f(Destination, fact.tokens)
       end
move top of Stack to the bottom
js
if (stacks[Stack]) {
        stacks[Stack].unshift(stacks[Stack].pop());
      }
merge Stack into a tuple on Destination
lua
local tuple = {}
       for _, fact in ipairs(stacks[Stack]) do
         table.insert(tuple, fact.tokens[1])
       end
       stacks[Stack] = nil
       f(Destination, tuple)
  
ruby
tuple = $stacks[stack].reduce [] do |tuple, fact|
          tuple << fact[:tokens][0]
        end
        $stacks.delete stack
        f destination, tuple