pyper 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pyper.rb +83 -1022
- data/lib/pyper/control_characters.rb +22 -0
- data/lib/pyper/control_characters/cadr_like.rb +241 -0
- data/lib/pyper/control_characters/greek_letters.rb +142 -0
- data/lib/pyper/control_characters/other.rb +379 -0
- data/lib/pyper/control_characters/other_latin_letters.rb +228 -0
- data/lib/pyper/default_includes.rb +46 -0
- data/lib/pyper/postfix_machine.rb +442 -0
- data/lib/pyper/postfix_machine/argument_source.rb +205 -0
- data/lib/pyper/version.rb +2 -2
- data/test/pyper_test.rb +45 -47
- metadata +9 -1
@@ -0,0 +1,22 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
|
3
|
+
# PostfixMachine mixin that defines the control characters.
|
4
|
+
#
|
5
|
+
module Pyper::ControlCharacters
|
6
|
+
PREFIX_CHARACTERS =
|
7
|
+
['t'] << # letter t (for "to_something" methods)
|
8
|
+
'o' << # letter o (for operators)
|
9
|
+
'l' << # letter l (for literals)
|
10
|
+
'i' << # letter i
|
11
|
+
'ι' << # greek iota
|
12
|
+
'¿' << # inverted question mark
|
13
|
+
'‹' << # single left pointing quotation mark
|
14
|
+
'›' << # single right pointing quotation mark
|
15
|
+
'﹕' << # small colon
|
16
|
+
'﹡' # small asterisk
|
17
|
+
end
|
18
|
+
|
19
|
+
require_relative 'control_characters/cadr_like'
|
20
|
+
require_relative 'control_characters/other_latin_letters'
|
21
|
+
require_relative 'control_characters/greek_letters'
|
22
|
+
require_relative 'control_characters/other'
|
@@ -0,0 +1,241 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
|
3
|
+
module Pyper::ControlCharacters
|
4
|
+
# In Pyper, 'car' becomes 'τaτ', and means second elements. Usable with
|
5
|
+
# strings, too.
|
6
|
+
#
|
7
|
+
def a; pipe_2_variable; start "#@r =\n" +
|
8
|
+
"if #@r.respond_to?( :first ) then #@r.first\n" +
|
9
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0]\n" +
|
10
|
+
"else raise 'impossible to extract first element' end"
|
11
|
+
start
|
12
|
+
end
|
13
|
+
|
14
|
+
# Means second element.
|
15
|
+
#
|
16
|
+
def b; pipe_2_variable; start "#@r =\n" +
|
17
|
+
"if #@r.respond_to?( :take ) then #@r.take(2)[1]\n" +
|
18
|
+
"elsif #@r.respond_to?( :[] ) then #@r[1]\n" +
|
19
|
+
"else raise 'unable to extract second collection element' end"
|
20
|
+
start
|
21
|
+
end
|
22
|
+
|
23
|
+
# Means third element.
|
24
|
+
#
|
25
|
+
def c; pipe_2_variable; start "#@r =\n" +
|
26
|
+
"if #@r.respond_to?( :take ) then #@r.take(3)[2]\n" +
|
27
|
+
"elsif #@r.respond_to?( :[] ) then #@r[2]\n" +
|
28
|
+
"else raise 'unable to extract third collection element' end"
|
29
|
+
start
|
30
|
+
end
|
31
|
+
|
32
|
+
# In Pyper, 'cdr' becomes 'τdτ'.
|
33
|
+
#
|
34
|
+
def d; pipe_2_variable; start "#@r =\n" +
|
35
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.drop(1) ]\n" +
|
36
|
+
"elsif #@r.respond_to?( :drop ) then #@r.drop(1)\n" +
|
37
|
+
"elsif #@r.respond_to?( :[] ) then #@r[1..-1]\n" +
|
38
|
+
"else raise 'unable to #drop(1) or #[1..-1]' end"
|
39
|
+
start
|
40
|
+
end
|
41
|
+
|
42
|
+
# Means all except the first 2 elements.
|
43
|
+
#
|
44
|
+
def e; pipe_2_variable; start "#@r =\n" +
|
45
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.drop(2) ]\n" +
|
46
|
+
"elsif #@r.respond_to?( :drop ) then #@r.drop(2)\n" +
|
47
|
+
"elsif #@r.respond_to?( :[] ) then #@r[2..-1]\n" +
|
48
|
+
"else raise 'unable to #drop(2) or #[2..-1]' end"
|
49
|
+
start
|
50
|
+
end
|
51
|
+
|
52
|
+
# Means all except the first 3 elements.
|
53
|
+
#
|
54
|
+
def f; pipe_2_variable; start "#@r =\n" +
|
55
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.drop(3) ]\n" +
|
56
|
+
"elsif #@r.respond_to?( :drop ) then #@r.drop(3)\n" +
|
57
|
+
"elsif #@r.respond_to?( :[] ) then #@r[3..-1]\n" +
|
58
|
+
"else raise 'unable to #drop(3) or #[3..-1]' end"
|
59
|
+
start
|
60
|
+
end
|
61
|
+
|
62
|
+
# Means the last collection element.
|
63
|
+
#
|
64
|
+
def z; pipe_2_variable; start "#@r =\n" +
|
65
|
+
"if #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 1 ).first\n" +
|
66
|
+
"elsif #@r.respond_to?( :[] ) then #@r[-1]\n" +
|
67
|
+
"else raise 'unable to extract last element' end"
|
68
|
+
start
|
69
|
+
end
|
70
|
+
|
71
|
+
# Means the penultimate collection element.
|
72
|
+
#
|
73
|
+
def y; pipe_2_variable; start "#@r =\n" +
|
74
|
+
"if #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 2 ).first\n" +
|
75
|
+
"elsif #@r.respond_to?( :[] ) then #@r[-2]\n" +
|
76
|
+
"else raise 'unable to extract second-from-the-end element' end"
|
77
|
+
start
|
78
|
+
end
|
79
|
+
|
80
|
+
# Means the third collection element from the end.
|
81
|
+
#
|
82
|
+
def x; pipe_2_variable; start "#@r =\n" +
|
83
|
+
"if #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 3 ).first\n" +
|
84
|
+
"elsif #@r.respond_to?( :[] ) then #@r[-3]\n" +
|
85
|
+
"else raise 'unable to extract third-from-the-end element' end"
|
86
|
+
start
|
87
|
+
end
|
88
|
+
|
89
|
+
# Whole collection except the last element,
|
90
|
+
#
|
91
|
+
def w; pipe_2_variable; start "#@r =\n" +
|
92
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.take( #@r.size - 1 ) ]\n" +
|
93
|
+
"elsif #@r.respond_to?( :take ) then #@r.take( #@r.size - 1 )\n" +
|
94
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0...-1]\n" +
|
95
|
+
"else raise 'unable to #drop(1) or #[1...-1]' end"
|
96
|
+
start
|
97
|
+
end
|
98
|
+
|
99
|
+
# Collection except the last 2 elements.
|
100
|
+
#
|
101
|
+
def v; pipe_2_variable; start "#@r =\n" +
|
102
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.take( #@r.size - 2 ) ]\n" +
|
103
|
+
"elsif #@r.respond_to?( :take ) then #@r.take( #@r.size - 2 )\n" +
|
104
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0...-2]\n" +
|
105
|
+
"else raise 'unable to #drop(1) or #[1...-2]' end"
|
106
|
+
start
|
107
|
+
end
|
108
|
+
|
109
|
+
# Collection except the last 3 elements.
|
110
|
+
#
|
111
|
+
def u; pipe_2_variable; start "#@r =\n" +
|
112
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.take( #@r.size - 3 ) ]\n" +
|
113
|
+
"elsif #@r.respond_to?( :take ) then #@r.take( #@r.size - 3 )\n" +
|
114
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0...-3]\n" +
|
115
|
+
"else raise 'unable to #drop(1) or #[1...-3]' end"
|
116
|
+
start
|
117
|
+
end
|
118
|
+
|
119
|
+
# Control character '0' means a singleton array containing the 1st element.
|
120
|
+
# of the collection.
|
121
|
+
#
|
122
|
+
self.send :define_method, :'0' do
|
123
|
+
pipe_2_variable; start "#@r =\n" +
|
124
|
+
"if #@r.is_a?( Hash ) then Hash[@r.take(1)]\n" +
|
125
|
+
"elsif #@r.respond_to?( :take ) then #@r.take(1)\n" +
|
126
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0..0]\n" +
|
127
|
+
"else raise 'unable to #take(1) or #[0..0]' end"
|
128
|
+
start
|
129
|
+
end
|
130
|
+
|
131
|
+
# Control character '1' means an array containing the [1st, 2nd] elements.
|
132
|
+
#
|
133
|
+
self.send :define_method, :'1' do
|
134
|
+
pipe_2_variable; start "#@r =\n" +
|
135
|
+
"if #@r.is_a?( Hash ) then Hash[@r.take(2)]\n" +
|
136
|
+
"elsif #@r.respond_to?( :take ) then #@r.take(2)\n" +
|
137
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0..1]\n" +
|
138
|
+
"else raise 'unable to #take(2) or #[0..1]' end"
|
139
|
+
start
|
140
|
+
end
|
141
|
+
|
142
|
+
# Control character '2' means an array of [1st, 2nd, 3rd] elements.
|
143
|
+
#
|
144
|
+
self.send :define_method, :'2' do
|
145
|
+
pipe_2_variable; start "#@r =\n" +
|
146
|
+
"if #@r.is_a?( Hash ) then Hash[@r.take(3)]\n" +
|
147
|
+
"elsif #@r.respond_to?( :take ) then #@r.take(3)\n" +
|
148
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0..2]\n" +
|
149
|
+
"else raise 'unable to #take(3) or #[0..2]' end"
|
150
|
+
start
|
151
|
+
end
|
152
|
+
|
153
|
+
# Control character '3' means an array of [1st, 2nd, 3rd, 4th] elements.
|
154
|
+
#
|
155
|
+
self.send :define_method, :'3' do
|
156
|
+
pipe_2_variable; start "#@r =\n" +
|
157
|
+
"if #@r.is_a?( Hash ) then Hash[@r.take(4)]\n" +
|
158
|
+
"elsif #@r.respond_to?( :take ) then #@r.take(4)\n" +
|
159
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0..3]\n" +
|
160
|
+
"else raise 'unable to #take(4) or #[0..3]' end"
|
161
|
+
start
|
162
|
+
end
|
163
|
+
|
164
|
+
# Control character '4' means an array of [1st, 2nd, 3rd, 4th, 5th] elements.
|
165
|
+
#
|
166
|
+
self.send :define_method, :'4' do
|
167
|
+
pipe_2_variable; start "#@r =\n" +
|
168
|
+
"if #@r.is_a?( Hash ) then Hash[@r.take(5)]\n" +
|
169
|
+
"elsif #@r.respond_to?( :take ) then #@r.take(5)\n" +
|
170
|
+
"elsif #@r.respond_to?( :[] ) then #@r[0..4]\n" +
|
171
|
+
"else raise 'unable to #take(5) or #[0..4]' end"
|
172
|
+
start
|
173
|
+
end
|
174
|
+
|
175
|
+
# Control char. '5' means an array of [-5th, -4th, -3rd, -2nd, -1st] elements
|
176
|
+
# (that is, the last 5 elements).
|
177
|
+
#
|
178
|
+
self.send :define_method, :'5' do
|
179
|
+
pipe_2_variable; start "#@r =\n" +
|
180
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.drop( #@r.size - 5 ) ]\n" +
|
181
|
+
"elsif #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 5 )\n" +
|
182
|
+
"elsif #@r.respond_to?( :[] ) then #@r[-5..-1]\n" +
|
183
|
+
"else raise 'unable to take last 5 or call #[-5..-1]' end"
|
184
|
+
start
|
185
|
+
end
|
186
|
+
|
187
|
+
# Control char. '6' means an array of [-4th, -3rd, -2nd, -1st] elements (that
|
188
|
+
# is, the last 4 elements).
|
189
|
+
#
|
190
|
+
self.send :define_method, :'6' do
|
191
|
+
pipe_2_variable; start "#@r =\n" +
|
192
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.drop( #@r.size - 4 ) ]\n" +
|
193
|
+
"elsif #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 4 )\n" +
|
194
|
+
"elsif #@r.respond_to?( :[] ) then #@r[-4..-1]\n" +
|
195
|
+
"else raise 'unable to take last 4 or call #[-4..-1]' end"
|
196
|
+
start
|
197
|
+
end
|
198
|
+
|
199
|
+
# Control char. '7' means an array of [-3rd, -2nd, -1st] elements (that is,
|
200
|
+
# the last 3 elements).
|
201
|
+
#
|
202
|
+
self.send :define_method, :'7' do
|
203
|
+
pipe_2_variable; start "#@r =\n" +
|
204
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.drop( #@r.size - 3 ) ]\n" +
|
205
|
+
"elsif #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 3 )\n" +
|
206
|
+
"elsif #@r.respond_to?( :[] ) then #@r[-3..-1]\n" +
|
207
|
+
"else raise 'unable to take last 3 or call #[-3..-1]' end"
|
208
|
+
start
|
209
|
+
end
|
210
|
+
|
211
|
+
# Control char. '8' means an array of [-2nd, -1st] elements (that is, the last
|
212
|
+
# 2 elements).
|
213
|
+
#
|
214
|
+
self.send :define_method, :'8' do
|
215
|
+
pipe_2_variable; start "#@r =\n" +
|
216
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.drop( #@r.size - 2 ) ]\n" +
|
217
|
+
"elsif #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 2 )\n" +
|
218
|
+
"elsif #@r.respond_to?( :[] ) then #@r[-2..-1]\n" +
|
219
|
+
"else raise 'unable to take last 2 or call #[-2..-1]' end"
|
220
|
+
start
|
221
|
+
end
|
222
|
+
|
223
|
+
# Control char. '9' means a singleton array containing the last element of a
|
224
|
+
# collection.
|
225
|
+
#
|
226
|
+
self.send :define_method, :'9' do
|
227
|
+
pipe_2_variable; start "#@r =\n" +
|
228
|
+
"if #@r.is_a?( Hash ) then Hash[ @r.drop( #@r.size - 1 ) ]\n" +
|
229
|
+
"elsif #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 1 )\n" +
|
230
|
+
"elsif #@r.respond_to?( :[] ) then #@r[-1..-1]\n" +
|
231
|
+
"else raise 'unable to take last 1 or call #[-1..-1]' end"
|
232
|
+
start
|
233
|
+
end
|
234
|
+
|
235
|
+
# (Remark: In the method definitions above, the message sent to the
|
236
|
+
# PostfixMachine instance consist of a single digit. Due to the
|
237
|
+
# syntactic rules, it is not possible to define these methods with 'def'
|
238
|
+
# statement. Also, these methods cannot be invoked by ordinary means,
|
239
|
+
# only by explicit message passing. This limitation is fine for this
|
240
|
+
# particular usecase.)
|
241
|
+
end # class Pyper::ControlCharacters
|
@@ -0,0 +1,142 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
|
3
|
+
module Pyper::ControlCharacters
|
4
|
+
# Pushes the primary register (alpha) on the argument source stack.
|
5
|
+
#
|
6
|
+
def α
|
7
|
+
@argsrc.alpha
|
8
|
+
end
|
9
|
+
|
10
|
+
# Stashes the contents of the primary pipeline to the argument stack, and
|
11
|
+
# sets the secondary register as the argument source.
|
12
|
+
#
|
13
|
+
def β
|
14
|
+
G()
|
15
|
+
r()
|
16
|
+
end
|
17
|
+
|
18
|
+
# A combo that switches this an the other register and sets the other register
|
19
|
+
# as the argument source.
|
20
|
+
#
|
21
|
+
def γ
|
22
|
+
X()
|
23
|
+
r()
|
24
|
+
end
|
25
|
+
|
26
|
+
# Pushes the in-block register (delta) on the argument source stack.
|
27
|
+
#
|
28
|
+
def δ
|
29
|
+
@argsrc.delta
|
30
|
+
end
|
31
|
+
|
32
|
+
# Pushes the block argument register 1 (epsilon) on the argument source stack.
|
33
|
+
#
|
34
|
+
def ε
|
35
|
+
@argsrc.epsilon
|
36
|
+
end
|
37
|
+
|
38
|
+
# Pushes the block argument register 2 (zeta) on the argument source stack.
|
39
|
+
#
|
40
|
+
def ζ
|
41
|
+
@argsrc.zeta
|
42
|
+
end
|
43
|
+
|
44
|
+
# Pushes onto the argument stack the default argument source, which is the
|
45
|
+
# "counted argument list" -- Pyper method argument array indexed by
|
46
|
+
# compile-time @arg_count index.
|
47
|
+
#
|
48
|
+
def λ
|
49
|
+
@argsrc.args_counted
|
50
|
+
end
|
51
|
+
|
52
|
+
# Pushes the penultimate element of the Pyper method argument array on the
|
53
|
+
# argument source stack.
|
54
|
+
#
|
55
|
+
def ψ
|
56
|
+
@argsrc.psi
|
57
|
+
end
|
58
|
+
|
59
|
+
# Pushes the last element of the Pyper method argument array on the argument
|
60
|
+
# source stack.
|
61
|
+
#
|
62
|
+
def ω
|
63
|
+
@argsrc.omega
|
64
|
+
end
|
65
|
+
|
66
|
+
# Small rho (ρ) sets the +:ref+ grab mode for the argument source stack --
|
67
|
+
# that is, turns off +:shift+ or +:dup+ mode when active.
|
68
|
+
#
|
69
|
+
def ρ
|
70
|
+
@argsrc.ref!
|
71
|
+
end
|
72
|
+
|
73
|
+
# Small sigma sets the 'shift' grab mode for the top @argsrc element.
|
74
|
+
#
|
75
|
+
def σ
|
76
|
+
@argsrc.shift!
|
77
|
+
end
|
78
|
+
|
79
|
+
# Capital pi (Π( sets the +:dup+ grab mode for the top @argsrc element.
|
80
|
+
#
|
81
|
+
def Π
|
82
|
+
@argsrc.dup!
|
83
|
+
end
|
84
|
+
|
85
|
+
# Pushes onto the stack the whole array of the arguments passed to the pyper
|
86
|
+
# method, with +:shift+ grab method turned on by default.
|
87
|
+
#
|
88
|
+
def Ω
|
89
|
+
@argsrc.args
|
90
|
+
end
|
91
|
+
|
92
|
+
# When Greek iota (ι) is used as the prefix to the source selector, then
|
93
|
+
# rather then being pushed on the @argsrc stack, the new argument source
|
94
|
+
# replaces the topmost element of the stack. When the stack size is 1, this
|
95
|
+
# has the additional effect of setting the given argument source as default,
|
96
|
+
# until another such change happens, or stack reset is performed.
|
97
|
+
|
98
|
+
def ια
|
99
|
+
@argsrc.alpha!
|
100
|
+
end
|
101
|
+
|
102
|
+
def ιβ
|
103
|
+
@argsrc.beta!
|
104
|
+
end
|
105
|
+
|
106
|
+
# def ιγ; @argsrc.var! successor_register( @rr[0] ) end
|
107
|
+
|
108
|
+
def ιδ
|
109
|
+
@argsrc.delta!
|
110
|
+
end
|
111
|
+
|
112
|
+
def ιε
|
113
|
+
@argsrc.epsilon!
|
114
|
+
end
|
115
|
+
|
116
|
+
def ιζ
|
117
|
+
@argsrc.zeta!
|
118
|
+
end
|
119
|
+
|
120
|
+
# Iota-prefixed rho (ιρ) resets the @argsrc stack to its default contents,
|
121
|
+
# that is, size 1 stack with +source:+ +:args_counted+, +grab_method:+ +:ref+.
|
122
|
+
#
|
123
|
+
def ιρ
|
124
|
+
@argsrc.std!
|
125
|
+
end
|
126
|
+
|
127
|
+
def ιψ
|
128
|
+
@argsrc.psi!
|
129
|
+
end
|
130
|
+
|
131
|
+
def ιω
|
132
|
+
@argsrc.omega!
|
133
|
+
end
|
134
|
+
|
135
|
+
def ιλ
|
136
|
+
@argsrc.args_counted!
|
137
|
+
end
|
138
|
+
|
139
|
+
def ιΩ
|
140
|
+
@argsrc.args!
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,379 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
|
3
|
+
module Pyper::ControlCharacters
|
4
|
+
# Nullary method join.
|
5
|
+
#
|
6
|
+
def ij
|
7
|
+
chain "join"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Unary + operator.
|
11
|
+
#
|
12
|
+
def ip
|
13
|
+
unary_operator "+"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Unary - operator.
|
17
|
+
#
|
18
|
+
def im
|
19
|
+
unary_operator "-"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Unary tilde operator.
|
23
|
+
#
|
24
|
+
def it
|
25
|
+
unary_operator "~"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Unary method +#index+.
|
29
|
+
#
|
30
|
+
def ix
|
31
|
+
unary_method "index"
|
32
|
+
end
|
33
|
+
|
34
|
+
# Nullary method +#compact+.
|
35
|
+
#
|
36
|
+
def iC
|
37
|
+
nullary_method "compact"
|
38
|
+
end
|
39
|
+
|
40
|
+
# Nullary method bang (+#!+, exclamation mark operator).
|
41
|
+
#
|
42
|
+
def iE
|
43
|
+
unary_operator '!'
|
44
|
+
end
|
45
|
+
|
46
|
+
# Map with index
|
47
|
+
#
|
48
|
+
def iX
|
49
|
+
next_block_will_be_binary
|
50
|
+
nullary_method "map"
|
51
|
+
nullary_method_with_block "with_index"
|
52
|
+
end
|
53
|
+
|
54
|
+
# Stands for Float( register ).
|
55
|
+
#
|
56
|
+
def tf
|
57
|
+
pipe_2_variable
|
58
|
+
start "Float( #@r )"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Make a hash out of the current register.
|
62
|
+
#
|
63
|
+
def th
|
64
|
+
pipe_2_variable
|
65
|
+
start "Hash[ #@r.zip( #{successor_register(@r)} ) ]"
|
66
|
+
end
|
67
|
+
|
68
|
+
# Stands for Integer( register ).
|
69
|
+
#
|
70
|
+
def ti
|
71
|
+
pipe_2_variable
|
72
|
+
start "Integer( #@r )"
|
73
|
+
end
|
74
|
+
|
75
|
+
# Stands for +#to_s+.
|
76
|
+
#
|
77
|
+
def ts
|
78
|
+
nullary_method "to_s"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Make a singleton array out of the current register. ("Array( register ) is
|
82
|
+
# invoked simply by capital A without prefixes.)
|
83
|
+
#
|
84
|
+
def tA
|
85
|
+
pipe_2_variable
|
86
|
+
start "[#@r]"
|
87
|
+
end
|
88
|
+
|
89
|
+
# Zips this and other register to a hash.
|
90
|
+
#
|
91
|
+
def tH
|
92
|
+
pipe_2_variable
|
93
|
+
start "Hash[ #@r.zip( #{successor_register( @r )} ) ]"
|
94
|
+
end
|
95
|
+
|
96
|
+
# Stands for +#to_sym+.
|
97
|
+
#
|
98
|
+
def tS
|
99
|
+
nullary_method "to_sym"
|
100
|
+
end
|
101
|
+
|
102
|
+
# Controlling block writing
|
103
|
+
# ********************************************************************
|
104
|
+
# Certain command characters cause writing a block opening. This block
|
105
|
+
# has certain arity (1 or 2), and is closed either automatically closed
|
106
|
+
# at the end of the command character sequence, or it can be closed
|
107
|
+
# explicitly earlier.
|
108
|
+
|
109
|
+
# Next block arity 2 selection
|
110
|
+
def ²; block_2ary end
|
111
|
+
|
112
|
+
# Superscript i. Next block will have arity 2 and will be written with
|
113
|
+
# inverse parameter order.
|
114
|
+
def ⁱ; block_2ary_swapped end
|
115
|
+
|
116
|
+
# Explicit block closing.
|
117
|
+
def _
|
118
|
+
case @w # close block when in :block
|
119
|
+
when :block then
|
120
|
+
chain( close_block )
|
121
|
+
@w = :main if @rr.size == 1 unless @rr.empty?
|
122
|
+
else raise "'_' (close block) used when not in block" end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Maps the other register to this register.
|
126
|
+
#
|
127
|
+
def iM
|
128
|
+
pipe_2_variable
|
129
|
+
start "#{successor_register(@r)}"
|
130
|
+
nullary_method_with_block "map"
|
131
|
+
end
|
132
|
+
|
133
|
+
def ᴘ # make a pair
|
134
|
+
pipe_2_variable
|
135
|
+
arg = grab_arg
|
136
|
+
start "[#@r, #{arg}]"
|
137
|
+
end
|
138
|
+
|
139
|
+
# Addition as unary method.
|
140
|
+
#
|
141
|
+
def oa
|
142
|
+
binary_operator "+"
|
143
|
+
end
|
144
|
+
alias ₊ oa # subscript plus (₊)
|
145
|
+
|
146
|
+
# Unary method +#include?+.
|
147
|
+
#
|
148
|
+
def oi
|
149
|
+
unary_method "include?"
|
150
|
+
end
|
151
|
+
|
152
|
+
# Subtraction as unary method.
|
153
|
+
#
|
154
|
+
def os
|
155
|
+
binary_operator "-"
|
156
|
+
end
|
157
|
+
alias ₋ os # subscript minus (₋)
|
158
|
+
|
159
|
+
# Multiplication as unary method.
|
160
|
+
#
|
161
|
+
def om
|
162
|
+
binary_operator "*"
|
163
|
+
end
|
164
|
+
alias ★ om
|
165
|
+
|
166
|
+
# Division as unary method.
|
167
|
+
#
|
168
|
+
def od
|
169
|
+
binary_operator "/"
|
170
|
+
end
|
171
|
+
alias ÷ od
|
172
|
+
|
173
|
+
# Power as unary method.
|
174
|
+
#
|
175
|
+
def op
|
176
|
+
binary_operator "**"
|
177
|
+
end
|
178
|
+
alias ﹡﹡ op
|
179
|
+
|
180
|
+
# And operator (+#&&+, double pretzel) method.
|
181
|
+
#
|
182
|
+
def oA
|
183
|
+
binary_operator "&&"
|
184
|
+
end
|
185
|
+
|
186
|
+
# Operator triple equals (+#===+).
|
187
|
+
#
|
188
|
+
def oA
|
189
|
+
binary_operator "==="
|
190
|
+
end
|
191
|
+
|
192
|
+
# Pipe operator (+#|+) method.
|
193
|
+
#
|
194
|
+
def oI
|
195
|
+
binary_operator "|"
|
196
|
+
end
|
197
|
+
|
198
|
+
# Smaller than as unary method.
|
199
|
+
#
|
200
|
+
def oS
|
201
|
+
binary_operator "<"
|
202
|
+
end
|
203
|
+
alias ﹤ oS
|
204
|
+
|
205
|
+
# Greater than as unary method.
|
206
|
+
#
|
207
|
+
def oG
|
208
|
+
binary_operator ">"
|
209
|
+
end
|
210
|
+
alias ﹥ oG
|
211
|
+
|
212
|
+
# Modulo operator as unary method (also used for string interpolation).
|
213
|
+
#
|
214
|
+
def oM
|
215
|
+
binary_operator "%"
|
216
|
+
end
|
217
|
+
|
218
|
+
# Or operator (+#||+, double pipe) method.
|
219
|
+
#
|
220
|
+
def oO
|
221
|
+
binary_operator "||"
|
222
|
+
end
|
223
|
+
|
224
|
+
# Pretzel operator (+#&+) method.
|
225
|
+
#
|
226
|
+
def o8
|
227
|
+
binary_operator "&"
|
228
|
+
end
|
229
|
+
|
230
|
+
# Smaller or equal as unary method.
|
231
|
+
#
|
232
|
+
def ιS
|
233
|
+
binary_operator "<="
|
234
|
+
end
|
235
|
+
|
236
|
+
# Greater or equal as unary method.
|
237
|
+
#
|
238
|
+
def ιG
|
239
|
+
binary_operator ">="
|
240
|
+
end
|
241
|
+
|
242
|
+
# Braces equals method, +#[]=+.
|
243
|
+
#
|
244
|
+
def ιI
|
245
|
+
@pipe[-1] << "[#{grab_arg}] = #{grab_arg}"
|
246
|
+
end
|
247
|
+
|
248
|
+
# Misc
|
249
|
+
# ********************************************************************
|
250
|
+
|
251
|
+
# def ru; end # unsh/prep reg 2 self (this changed)
|
252
|
+
# def rv; end # <</app reg 2 self (this changed)
|
253
|
+
# def rU; end # unsh/prep reg 2 self (other changed)
|
254
|
+
# def rV; end # <</app reg 2 self (other changed)
|
255
|
+
|
256
|
+
# def su; end # unsh/prep self 2 arg
|
257
|
+
# def sv; end # <</app self 2 arg
|
258
|
+
|
259
|
+
# def sy; nullary_method "to_sym" end
|
260
|
+
|
261
|
+
# # sA: ? prependmap other, this, switch to other
|
262
|
+
# # sB: ? appendmap other, this, switch to other
|
263
|
+
|
264
|
+
# def sU; end #
|
265
|
+
# def sV; end
|
266
|
+
|
267
|
+
# Argument-setting literal +nil+.
|
268
|
+
#
|
269
|
+
def ιn
|
270
|
+
exe "args.unshift %s" % "nil"
|
271
|
+
end
|
272
|
+
|
273
|
+
# Argument-setting literal +''+.
|
274
|
+
#
|
275
|
+
def ις;
|
276
|
+
exe "args.unshift %s" % ''
|
277
|
+
end
|
278
|
+
|
279
|
+
# Argument-setting literal +[]+.
|
280
|
+
#
|
281
|
+
def ιA
|
282
|
+
exe "args.unshift %s" % '[]'
|
283
|
+
end
|
284
|
+
|
285
|
+
# Argument-setting literal +{}+.
|
286
|
+
#
|
287
|
+
def ιH
|
288
|
+
exe "args.unshift %s" % '{}'
|
289
|
+
end
|
290
|
+
|
291
|
+
# Pipe-resetting literal +nil+.
|
292
|
+
#
|
293
|
+
def ln
|
294
|
+
set "nil"
|
295
|
+
end
|
296
|
+
|
297
|
+
# Pipe-resetting literal empty string +''+.
|
298
|
+
#
|
299
|
+
def lς
|
300
|
+
set ''
|
301
|
+
end
|
302
|
+
|
303
|
+
# Pipe-resetting literal empty array +[]+.
|
304
|
+
#
|
305
|
+
def lA
|
306
|
+
set '[]'
|
307
|
+
end
|
308
|
+
|
309
|
+
# Pipe-resetting literal empty hash +{}+.
|
310
|
+
#
|
311
|
+
def lH
|
312
|
+
set '{}'
|
313
|
+
end
|
314
|
+
|
315
|
+
# Pipe-resetting literal digit 0.
|
316
|
+
#
|
317
|
+
def l0
|
318
|
+
set "0"
|
319
|
+
end
|
320
|
+
|
321
|
+
# Pipe-resetting literal digit 1.
|
322
|
+
#
|
323
|
+
def l1
|
324
|
+
set "1"
|
325
|
+
end
|
326
|
+
|
327
|
+
# Pipe-resetting literal digit 2.
|
328
|
+
#
|
329
|
+
def l2
|
330
|
+
set "2"
|
331
|
+
end
|
332
|
+
|
333
|
+
# Pipe-resetting literal digit 3.
|
334
|
+
#
|
335
|
+
def l3
|
336
|
+
set "3"
|
337
|
+
end
|
338
|
+
|
339
|
+
# Pipe-resetting literal digit 4.
|
340
|
+
#
|
341
|
+
def l4
|
342
|
+
set "4"
|
343
|
+
end
|
344
|
+
|
345
|
+
# Pipe-resetting literal digit 5.
|
346
|
+
#
|
347
|
+
def l5
|
348
|
+
set "5"
|
349
|
+
end
|
350
|
+
|
351
|
+
# Pipe-resetting literal digit 6.
|
352
|
+
#
|
353
|
+
def l6
|
354
|
+
set "6"
|
355
|
+
end
|
356
|
+
|
357
|
+
# Pipe-resetting literal digit 7.
|
358
|
+
#
|
359
|
+
def l7
|
360
|
+
set "7"
|
361
|
+
end
|
362
|
+
|
363
|
+
# Pipe-resetting literal digit 8.
|
364
|
+
#
|
365
|
+
def l8
|
366
|
+
set "8"
|
367
|
+
end
|
368
|
+
|
369
|
+
# Pipe-resetting literal digit 9.
|
370
|
+
#
|
371
|
+
def l9
|
372
|
+
set "9"
|
373
|
+
end
|
374
|
+
|
375
|
+
# Clear the current pipe (set to empty string):
|
376
|
+
def ∅; set "" end
|
377
|
+
alias :⊘ :∅ # similarly looking circled slash
|
378
|
+
alias :ø :∅ # similarly looking Danish ø
|
379
|
+
end
|