rpl.rb/lib/rpl/core/list.rb
Gwenhael Le Moine 8b07724e50
make it a gem
2022-02-15 17:06:19 +01:00

33 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module RplLang
module Core
module List
def populate_dictionary
super
@dictionary.add_word( ['→list', '->list'],
'Lists',
'( … x -- […] ) pack x stacks levels into a list',
proc do
args = stack_extract( [%i[numeric]] )
args = stack_extract( %i[any] * args[0][:value] )
@stack << { type: :list,
value: args.reverse }
end )
@dictionary.add_word( ['list→', 'list->'],
'Lists',
'( […] -- … ) unpack list on stack',
proc do
args = stack_extract( [%i[list]] )
args[0][:value].each do |elt|
@stack << elt
end
end )
end
end
end
end