rpl.rb/lib/core/list.rb

26 lines
525 B
Ruby
Raw Normal View History

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