rpl 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +74 -0
- data/bin/rpl +8 -10
- data/lib/rpl/dictionary.rb +12 -12
- data/lib/rpl/interpreter.rb +4 -4
- data/lib/rpl/words/branch.rb +39 -39
- data/lib/rpl/words/display.rb +12 -12
- data/lib/rpl/words/filesystem.rb +25 -25
- data/lib/rpl/words/general.rb +32 -32
- data/lib/rpl/words/list.rb +34 -34
- data/lib/rpl/words/logarithm.rb +21 -21
- data/lib/rpl/words/mode.rb +24 -24
- data/lib/rpl/words/operations-complexes.rb +53 -53
- data/lib/rpl/words/operations-reals-complexes.rb +185 -185
- data/lib/rpl/words/operations-reals.rb +105 -105
- data/lib/rpl/words/program.rb +19 -19
- data/lib/rpl/words/repl.rb +65 -65
- data/lib/rpl/words/stack.rb +133 -133
- data/lib/rpl/words/store.rb +74 -74
- data/lib/rpl/words/string-list.rb +11 -11
- data/lib/rpl/words/string.rb +73 -73
- data/lib/rpl/words/test.rb +103 -103
- data/lib/rpl/words/time-date.rb +20 -20
- data/lib/rpl/words/trig.rb +47 -47
- data/lib/rpl.rb +3 -3
- metadata +6 -4
@@ -11,191 +11,191 @@ module RplLang
|
|
11
11
|
category = 'Usual operations on reals and complexes'
|
12
12
|
|
13
13
|
# Usual operations on reals and complexes
|
14
|
-
@dictionary.add_word( ['+'],
|
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
|
-
@dictionary.add_word( ['-'],
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
@dictionary.add_word( ['chs'],
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
@dictionary.add_word( ['×', '*'],
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
@dictionary.add_word( ['÷', '/'],
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
@dictionary.add_word( ['inv'],
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
@dictionary.add_word( ['^'],
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
@dictionary.add_word( ['√', 'sqrt'],
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
@dictionary.add_word( ['²', 'sq'],
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
@dictionary.add_word( ['abs'],
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
@dictionary.add_word( ['dec'],
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
@dictionary.add_word( ['hex'],
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
@dictionary.add_word( ['bin'],
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
@dictionary.add_word( ['base'],
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
@dictionary.add_word( ['sign'],
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
14
|
+
@dictionary.add_word!( ['+'],
|
15
|
+
category,
|
16
|
+
'( a b -- c ) addition',
|
17
|
+
proc do
|
18
|
+
addable = [RplNumeric, RplString, RplName, RplList]
|
19
|
+
args = stack_extract( [addable, addable] )
|
20
|
+
# | + | 1 numeric | 1 string | 1 name |v1 list |
|
21
|
+
# |-----------+-----------+----------+--------+--------|
|
22
|
+
# | 0 numeric | numeric | string | name |vlist |
|
23
|
+
# |v0 string |vstring |vstring |vstring |vlist |
|
24
|
+
# |v0 name |vstring |vstring |vname |vlist |
|
25
|
+
# |v0 list |vlist |vlist |vlist |vlist |
|
26
|
+
|
27
|
+
args.reverse!
|
28
|
+
|
29
|
+
result = if args[0].instance_of?( RplList )
|
30
|
+
new_list = if args[1].instance_of?( RplList )
|
31
|
+
RplList.new( args[0].to_s ).value.concat( args[1].value )
|
32
|
+
else
|
33
|
+
RplList.new( args[0].to_s ).value.concat( [args[1]] )
|
34
|
+
end
|
35
|
+
|
36
|
+
RplList.new( "{ #{new_list.join(' ')} }" )
|
37
|
+
|
38
|
+
elsif args[1].instance_of?( RplList )
|
39
|
+
new_list = if args[0].instance_of?( RplList )
|
40
|
+
RplList.new( args[0].to_s ).value.concat( args[1].value )
|
41
|
+
else
|
42
|
+
RplList.new( "{ #{args[0]} }" ).value.concat( args[1].value )
|
43
|
+
end
|
44
|
+
|
45
|
+
RplList.new( "{ #{new_list.join(' ')} }" )
|
46
|
+
|
47
|
+
elsif args[0].instance_of?( RplString )
|
48
|
+
RplString.new( if args[1].instance_of?( RplString ) ||
|
49
|
+
args[1].instance_of?( RplName )
|
50
|
+
"\"#{args[0].value}#{args[1].value}\""
|
51
|
+
else
|
52
|
+
"\"#{args[0].value}#{args[1]}\""
|
53
|
+
end )
|
54
|
+
|
55
|
+
elsif args[0].instance_of?( RplName )
|
56
|
+
|
57
|
+
if args[1].instance_of?( RplName )
|
58
|
+
RplName.new( "'#{args[0].value}#{args[1].value}'" )
|
59
|
+
elsif args[1].instance_of?( RplString )
|
60
|
+
Types.new_object( RplString, "\"#{args[0].value}#{args[1].value}\"" )
|
61
|
+
elsif args[1].instance_of?( RplNumeric )
|
62
|
+
RplName.new( "'#{args[0].value}#{args[1]}'" )
|
63
|
+
else
|
64
|
+
Types.new_object( RplString, "\"#{args[0]}#{args[1]}\"" )
|
65
|
+
end
|
66
|
+
|
67
|
+
elsif args[0].instance_of?( RplNumeric )
|
68
|
+
if args[1].instance_of?( RplNumeric )
|
69
|
+
RplNumeric.new( args[0].value + args[1].value, args[0].base )
|
70
|
+
elsif args[1].instance_of?( RplString )
|
71
|
+
RplString.new( "\"#{args[0]}#{args[1].value}\"" )
|
72
|
+
elsif args[1].instance_of?( RplName )
|
73
|
+
RplName.new( "'#{args[0]}#{args[1].value}'" )
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
@stack << result
|
78
|
+
end )
|
79
|
+
|
80
|
+
@dictionary.add_word!( ['-'],
|
81
|
+
category,
|
82
|
+
'( a b -- c ) subtraction',
|
83
|
+
proc do
|
84
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
85
|
+
|
86
|
+
@stack << RplNumeric.new( args[1].value - args[0].value, args[1].base )
|
87
|
+
end )
|
88
|
+
|
89
|
+
@dictionary.add_word!( ['chs'],
|
90
|
+
category,
|
91
|
+
'( a -- b ) negate',
|
92
|
+
proc do
|
93
|
+
run!( '-1 *' )
|
94
|
+
end )
|
95
|
+
|
96
|
+
@dictionary.add_word!( ['×', '*'],
|
97
|
+
category,
|
98
|
+
'( a b -- c ) multiplication',
|
99
|
+
proc do
|
100
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
101
|
+
|
102
|
+
@stack << RplNumeric.new( args[1].value * args[0].value, args[1].base )
|
103
|
+
end )
|
104
|
+
|
105
|
+
@dictionary.add_word!( ['÷', '/'],
|
106
|
+
category,
|
107
|
+
'( a b -- c ) division',
|
108
|
+
proc do
|
109
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
110
|
+
|
111
|
+
@stack << RplNumeric.new( args[1].value / args[0].value, args[1].base )
|
112
|
+
end )
|
113
|
+
|
114
|
+
@dictionary.add_word!( ['inv'],
|
115
|
+
category,
|
116
|
+
'( a -- b ) invert numeric',
|
117
|
+
proc do
|
118
|
+
run!( '1.0 swap /' )
|
119
|
+
end )
|
120
|
+
|
121
|
+
@dictionary.add_word!( ['^'],
|
122
|
+
category,
|
123
|
+
'( a b -- c ) a to the power of b',
|
124
|
+
proc do
|
125
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
126
|
+
|
127
|
+
@stack << RplNumeric.new( args[1].value**args[0].value, args[1].base )
|
128
|
+
end )
|
129
|
+
|
130
|
+
@dictionary.add_word!( ['√', 'sqrt'],
|
131
|
+
category,
|
132
|
+
'( a -- b ) square root',
|
133
|
+
proc do
|
134
|
+
args = stack_extract( [[RplNumeric]] )
|
135
|
+
|
136
|
+
@stack << RplNumeric.new( BigMath.sqrt( args[0].value, RplNumeric.precision ), args[0].base )
|
137
|
+
end )
|
138
|
+
|
139
|
+
@dictionary.add_word!( ['²', 'sq'],
|
140
|
+
category,
|
141
|
+
'( a -- b ) square',
|
142
|
+
proc do
|
143
|
+
run!( 'dup ×')
|
144
|
+
end )
|
145
|
+
|
146
|
+
@dictionary.add_word!( ['abs'],
|
147
|
+
category,
|
148
|
+
'( a -- b ) absolute value',
|
149
|
+
proc do
|
150
|
+
args = stack_extract( [[RplNumeric]] )
|
151
|
+
|
152
|
+
@stack << RplNumeric.new( args[0].value.abs, args[0].base )
|
153
|
+
end )
|
154
|
+
|
155
|
+
@dictionary.add_word!( ['dec'],
|
156
|
+
category,
|
157
|
+
'( a -- a ) set numeric\'s base to 10',
|
158
|
+
proc do
|
159
|
+
run!( '10 base' )
|
160
|
+
end )
|
161
|
+
|
162
|
+
@dictionary.add_word!( ['hex'],
|
163
|
+
category,
|
164
|
+
'( a -- a ) set numeric\'s base to 16',
|
165
|
+
proc do
|
166
|
+
run!( '16 base' )
|
167
|
+
end )
|
168
|
+
|
169
|
+
@dictionary.add_word!( ['bin'],
|
170
|
+
category,
|
171
|
+
'( a -- a ) set numeric\'s base to 2',
|
172
|
+
proc do
|
173
|
+
run!( '2 base' )
|
174
|
+
end )
|
175
|
+
|
176
|
+
@dictionary.add_word!( ['base'],
|
177
|
+
category,
|
178
|
+
'( a b -- a ) set numeric\'s base to b',
|
179
|
+
proc do
|
180
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
181
|
+
|
182
|
+
@stack << RplNumeric.new( args[1].value, args[0].value )
|
183
|
+
end )
|
184
|
+
|
185
|
+
@dictionary.add_word!( ['sign'],
|
186
|
+
category,
|
187
|
+
'( a -- b ) sign of element',
|
188
|
+
proc do
|
189
|
+
args = stack_extract( [[RplNumeric]] )
|
190
|
+
|
191
|
+
@stack << RplNumeric.new( if args[0].value.positive?
|
192
|
+
1
|
193
|
+
elsif args[0].value.negative?
|
194
|
+
-1
|
195
|
+
else
|
196
|
+
0
|
197
|
+
end )
|
198
|
+
end )
|
199
199
|
end
|
200
200
|
end
|
201
201
|
end
|
@@ -10,111 +10,111 @@ module RplLang
|
|
10
10
|
|
11
11
|
category = 'Operations on reals'
|
12
12
|
# Operations on reals
|
13
|
-
@dictionary.add_word( ['%'],
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@dictionary.add_word( ['%
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@dictionary.add_word( ['mod'],
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@dictionary.add_word( ['!', 'fact'],
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
@dictionary.add_word( ['floor'],
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
@dictionary.add_word( ['ceil'],
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
@dictionary.add_word( ['min'],
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@dictionary.add_word( ['max'],
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
@dictionary.add_word( ['mant'],
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
@dictionary.add_word( ['xpon'],
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
@dictionary.add_word( ['ip'],
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
@dictionary.add_word( ['fp'],
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
13
|
+
@dictionary.add_word!( ['%'],
|
14
|
+
category,
|
15
|
+
'( a b -- c ) b% of a',
|
16
|
+
proc do
|
17
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
18
|
+
|
19
|
+
@stack << RplNumeric.new( args[0].value * ( args[1].value / 100.0 ), args[1].base )
|
20
|
+
end )
|
21
|
+
|
22
|
+
@dictionary.add_word!( ['%ch'],
|
23
|
+
category,
|
24
|
+
'( a b -- c ) b is c% of a',
|
25
|
+
proc do
|
26
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
27
|
+
|
28
|
+
@stack << RplNumeric.new( 100.0 * ( args[0].value / args[1].value ), args[1].base )
|
29
|
+
end )
|
30
|
+
|
31
|
+
@dictionary.add_word!( ['mod'],
|
32
|
+
category,
|
33
|
+
'( a b -- c ) modulo',
|
34
|
+
proc do
|
35
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
36
|
+
|
37
|
+
@stack << RplNumeric.new( args[1].value % args[0].value, args[1].base )
|
38
|
+
end )
|
39
|
+
|
40
|
+
@dictionary.add_word!( ['!', 'fact'],
|
41
|
+
category,
|
42
|
+
'( a -- b ) factorial',
|
43
|
+
proc do
|
44
|
+
args = stack_extract( [[RplNumeric]] )
|
45
|
+
|
46
|
+
@stack << RplNumeric.new( Math.gamma( args[0].value ), args[0].base )
|
47
|
+
end )
|
48
|
+
|
49
|
+
@dictionary.add_word!( ['floor'],
|
50
|
+
category,
|
51
|
+
'( a -- b ) highest integer under a',
|
52
|
+
proc do
|
53
|
+
args = stack_extract( [[RplNumeric]] )
|
54
|
+
|
55
|
+
@stack << RplNumeric.new( args[0].value.floor, args[0].base )
|
56
|
+
end )
|
57
|
+
|
58
|
+
@dictionary.add_word!( ['ceil'],
|
59
|
+
category,
|
60
|
+
'( a -- b ) highest integer over a',
|
61
|
+
proc do
|
62
|
+
args = stack_extract( [[RplNumeric]] )
|
63
|
+
|
64
|
+
@stack << RplNumeric.new( args[0].value.ceil, args[0].base )
|
65
|
+
end )
|
66
|
+
|
67
|
+
@dictionary.add_word!( ['min'],
|
68
|
+
category,
|
69
|
+
'( a b -- a/b ) leave lowest of a or b',
|
70
|
+
proc do
|
71
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
72
|
+
|
73
|
+
@stack << ( args[0].value < args[1].value ? args[0] : args[1] )
|
74
|
+
end )
|
75
|
+
|
76
|
+
@dictionary.add_word!( ['max'],
|
77
|
+
category,
|
78
|
+
'( a b -- a/b ) leave highest of a or b',
|
79
|
+
proc do
|
80
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
81
|
+
|
82
|
+
@stack << ( args[0].value > args[1].value ? args[0] : args[1] )
|
83
|
+
end )
|
84
|
+
|
85
|
+
@dictionary.add_word!( ['mant'],
|
86
|
+
category,
|
87
|
+
'mantissa of a real number',
|
88
|
+
proc do
|
89
|
+
args = stack_extract( [[RplNumeric]] )
|
90
|
+
|
91
|
+
@stack << Types.new_object( RplNumeric, args[0].value.to_s.split('e').first.to_f.abs )
|
92
|
+
end )
|
93
|
+
|
94
|
+
@dictionary.add_word!( ['xpon'],
|
95
|
+
category,
|
96
|
+
'exponant of a real number',
|
97
|
+
proc do
|
98
|
+
args = stack_extract( [[RplNumeric]] )
|
99
|
+
|
100
|
+
@stack << RplNumeric.new( args[0].value.exponent, args[0].base )
|
101
|
+
end )
|
102
|
+
|
103
|
+
@dictionary.add_word!( ['ip'],
|
104
|
+
category,
|
105
|
+
'( n -- i ) integer part',
|
106
|
+
proc do
|
107
|
+
run!( 'dup fp -' )
|
108
|
+
end )
|
109
|
+
|
110
|
+
@dictionary.add_word!( ['fp'],
|
111
|
+
category,
|
112
|
+
'( n -- f ) fractional part',
|
113
|
+
proc do
|
114
|
+
args = stack_extract( [[RplNumeric]] )
|
115
|
+
|
116
|
+
@stack << RplNumeric.new( args[0].value.frac, args[0].base )
|
117
|
+
end )
|
118
118
|
end
|
119
119
|
end
|
120
120
|
end
|