Module: RplLang::Words::Program

Includes:
Types
Included in:
Rpl
Defined in:
lib/rpl/words/program.rb

Instance Method Summary collapse

Methods included from Types

new_object

Instance Method Details

#populate_dictionaryObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rpl/words/program.rb', line 8

def populate_dictionary
  super

  category = 'Program'

  @dictionary.add_word!( ['eval'],
                         category,
                         '( a -- … ) interpret',
                         proc do
                           args = stack_extract( [:any] )

                           if [RplList, RplNumeric, RplBoolean].include?( args[0].class )
                             @stack << args[0] # these types evaluate to themselves
                           else
                             run!( args[0].value.to_s )
                           end
                         end )

  @dictionary.add_word!( ['sheval'],
                         category,
                         '( string -- output ) run string in OS shell and put output on stack',
                         proc do
                           args = stack_extract( [[RplString]] )

                           @stack << Types.new_object( RplString, "\"#{`#{args[0].value}`}\"" )
                         end )

  @dictionary.add_word!( ['', 'lsto'],
                         category,
                         '( content name -- ) store to local variable',
                         proc do
                           args = stack_extract( [[RplName], :any] )

                           @dictionary.add_local_var!( args[0].value,
                                                       args[1] )
                         end )
end