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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/rpl/words/repl.rb', line 10
def populate_dictionary
super
category = 'REPL'
@dictionary.add_word!( ['words'],
category,
'() print the categorized list of all words',
proc do
@dictionary.words
.to_a
.group_by { |word| word.last[:category] }
.each do |cat, words|
puts cat
puts " #{words.map(&:first).join(', ')}"
end
end )
@dictionary.add_word!( ['history'],
category,
'() print the REPL\'s history',
proc {} )
@dictionary.add_word!( ['edit'],
category,
'( x -- y ) put first stack object in prompt for modification',
proc {} )
@dictionary.add_word!( ['extedit'],
category,
'( x -- y ) open object in $EDITOR',
proc do
args = ( [:any] )
value = args[0].to_s
tempfile = Tempfile.new('rpl')
begin
tempfile.write( value )
tempfile.rewind
`$EDITOR #{tempfile.path}`
edited_value = tempfile.read
ensure
tempfile.close
tempfile.unlink
end
@stack << Types.new_object( args[0].class, edited_value )
end )
category = 'DEBUG'
@dictionary.add_word!( ['.s'],
category,
'() print internal state of stack',
proc { pp @stack } )
@dictionary.add_word!( ['.d'],
category,
'() print internal state of dictionary',
proc { pp @dictionary } )
@dictionary.add_word!( ['.v'],
category,
'() print internal state of variables',
proc { pp @dictionary.vars } )
@dictionary.add_word!( ['.lv'],
category,
'() print internal state of local variables layers',
proc { pp @dictionary.local_vars_layers } )
end
|