rpl.rb/lib/rpl/words/program.rb

25 lines
739 B
Ruby
Raw Normal View History

2021-12-07 16:09:17 +01:00
# frozen_string_literal: true
module RplLang
module Words
module Program
def populate_dictionary
super
2021-11-18 12:00:02 +01:00
@dictionary.add_word( ['eval'],
'Program',
'( a -- … ) interpret',
proc do
args = stack_extract( [:any] )
2021-11-18 12:00:02 +01:00
2022-02-22 14:58:17 +01:00
if %i[list numeric boolean].include?( args[0][:type] )
2022-02-17 15:21:24 +01:00
@stack << args[0] # these types evaluate to themselves
else
run( args[0][:value].to_s )
end
end )
end
2021-11-18 12:00:02 +01:00
end
end
end