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

25 lines
525 B
Ruby

# frozen_string_literal: true
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