rpl.rb/lib/core/list.rb
2022-02-10 14:33:09 +01:00

27 lines
578 B
Ruby

# frozen_string_literal: true
module Rpl
module Lang
module Core
module_function
# ( … x -- […] ) pack x stacks levels into a list
def to_list
args = stack_extract( [%i[numeric]] )
args = stack_extract( %i[any] * args[0][:value] )
@stack << { type: :list,
value: args.reverse }
end
# ( […] -- … ) unpack list on stack
def unpack_list
args = stack_extract( [%i[list]] )
args[0][:value].each do |elt|
@stack << elt
end
end
end
end
end