Class: Pyper::PostfixMachine
- Inherits:
-
Object
- Object
- Pyper::PostfixMachine
- Defined in:
- lib/pyper.rb
Overview
PostfixMachine is an algorithmic writer of Pyper methods. Each Pyper method has two pipelines: ‘alpha’ (no. 0) and ‘beta’ (no. 1). Variables ‘alpha’ and ‘beta’ are local to the main scope of a Pyper method.
When blocks are used inside a Pyper method, variable ‘delta’ local to the block is used to hold the pipeline inside the block. For blocks with arity 1, variable named ‘epsilon’ is used to hold the block argument. For blocks with arity 2, variables named ‘epsilon’, resp. ‘zeta’ are used to hold 1st, resp. 2nd block argument. Blocks with arity higher than 2 are not allowed in Pyper methods. (However, Pyper methods may receive external block of arbitrary construction.)
Control characters are still under heavy development - presently, one must read the code to learn about their exact meaning.
Constant Summary collapse
- PREFIX_CHARACTERS =
['ℓ'] << # math script ℓ (as in litre) '¡' << # inverted exclamation mark '¿' << # inverted question mark '‹' << # single left pointing quotation mark '›' << # single right pointing quotation mark '﹦' << # small equals sign '﹕' << # small colon '﹡'
- SUCC =
small asterisk
{ alpha: :beta, beta: :alpha,
- PRE =
successor table
{ alpha: :beta, beta: :alpha,
- DEF_LINE =
Template for the def line of the method being written:
lambda { |
- ARG_SOURCES_AND_GRAB_METHODS =
The default source of arguments in Pyper methods is ‘args’ local variable, where arguments supplied to the Pyper methods are collected. However, this default argument source can be changed to something else. For this purpose, at write time of a Pyper method, stack is maintained, showing where the next argument will come from. The following closure is basically the constructor of this stack, which is implemented as a Hash with two keys :src and :grab, describing respectively the argument source, and what to do with it to obtain the required argument from it.
Possible argument source objects: :args (whole argument array), :args_counted (args referenced using a write-time counter - default) :alpha (primary pipeline) :beta (secondary pipeline) :delta (in-block pipeline) :epsilon (block argument 0) :zeta (block argument 1) :psi (penultimate element in the args array; penultimate argument) :omega (last element in the args array; last argument)
Argument grab methods: :ref (by simple reference to the object specified as the arg. source) :dup (by #dup of the object specified as the arg. sourc) :shift (by calling runtime #shift on the obj. spec. as the arg. src.)
So here goes the closure:
lambda { # We start from a ꜧ with 2 keys (:src & :grab) pointing to 2 ᴀs:
Instance Method Summary collapse
-
#_ ⇒ Object
Explicit block closing.
-
#_r_ ⇒ Object
Active register reader.
-
#a ⇒ Object
In Pyper, ‘car’ becomes ‘τaτ’, and applies to strings, too:.
-
#A ⇒ Object
(also: #Α)
Latin capital letters ********************************************************************.
-
#alpha_touch ⇒ Object
register 0 (alpha) was required for computation.
-
#autoclose_open_blocks_and_return ⇒ Object
After we run out of atomic commands, it’s time to finalize the program by closing any blocks still left open.
-
#b ⇒ Object
Extension of this idea: ‘b’ is 2nd, ‘c’ is 3rd:.
-
#B ⇒ Object
eat block.
-
#belay ⇒ Object
Store in active register, and continue in a new pipeline:.
-
#beta_autoinit ⇒ Object
(also: #beta_touch)
register 1 (beta) was required for the computation.
-
#bin_op(s, x = grab_arg) ⇒ Object
Write binary operator.
-
#binary_m(s, x = grab_arg, y = grab_arg) ⇒ Object
Chain binary method.
- #block(cmd) ⇒ Object
-
#block_2ary ⇒ Object
Next block will be written as binary:.
-
#block_2ary_swapped ⇒ Object
Next block will be writen as binary with swapped block arguments (delta = zeta; @argsrc.epsilon):.
- #c ⇒ Object
-
#C ⇒ Object
explicit parenthesize.
-
#chain(s) ⇒ Object
Chain (nullary) method string to the end of the pipe.
-
#close_block ⇒ Object
Called to close a block, including the main def.
-
#d ⇒ Object
In Pyper ‘cdr’ becomes ‘τdτ’:.
-
#D ⇒ Object
self.dup.
-
#e ⇒ Object
‘e’, ‘f’ mean all but first 2, resp.
-
#E ⇒ Object
-> g.
-
#exe(s) ⇒ Object
pipe_2_variable, execute something else, and go back to @r.
- #f ⇒ Object
-
#g ⇒ Object
Remaining latin letters ********************************************************************.
-
#grab_arg ⇒ Object
Writer of argument grab strings.
-
#h ⇒ Object
set pipe <- whole args array.
-
#H ⇒ Object
L.
-
#initialize(command_ς) ⇒ PostfixMachine
constructor
PostfixMachine initialization.
-
#initialize_writer_state ⇒ Object
Initialize method writing flags / state keepers.
-
#j ⇒ Object
i:.
-
#J ⇒ Object
binary join.
-
#m ⇒ Object
‘9’ - [-1st] (ie. an array with only the last collection element).
-
#M ⇒ Object
L:.
-
#main(cmd) ⇒ Object
Execution methods (depending on @w at the moment).
-
#maybe_block ⇒ Object
Returns nothing or optional block, if flagged to do so.
-
#nullary_m(s) ⇒ Object
Chain unary method.
-
#nullary_m_with_block(str) ⇒ Object
Initiates writing a block method.
-
#paren ⇒ Object
parethesize current pipe.
-
#parse_command_string(arg) ⇒ Object
Command ς -> command ᴀ.
-
#pipe_2_variable ⇒ Object
Suck the pipe into the “memory” (active register).
-
#R ⇒ Object
N: O: prefix character (ready to append literal) P: recursive piper method, begin Q: recursive piper method, end.
-
#rPRE(reg = @r) ⇒ Object
touch and return predecessor of a register, or @r by default.
-
#rSUCC(reg = @r) ⇒ Object
touch and return successor of a register, or @r by default.
-
#set(s) ⇒ Object
Set the pipe to a value, discarding current contents.
-
#start(s = "#@r") ⇒ Object
Start a new pipe, on a new line.
-
#U ⇒ Object
S: T: prefix character.
-
#u ⇒ Object
‘u’ - all except last 3.
- #unary_m(s, x = grab_arg) ⇒ Object
-
#unary_op(s) ⇒ Object
Write unary operator.
-
#v ⇒ Object
‘v’ - all except last 2.
-
#V ⇒ Object
unsh/prep self 2 reg (other changed).
-
#w ⇒ Object
‘w’ - all except last.
-
#W ⇒ Object
<</app self 2 reg (other changed).
-
#write(x) ⇒ Object
Append string to head.
-
#write_initial_pipeline ⇒ Object
Initialize the pipeline (@pipe).
-
#write_mτ(ɴ, opts = {}) ⇒ Object
Algorithmically writes a Ruby mτ, whose name is given as 1st arg., and the options ꜧ expects 2 keys (:op and :ret) as follows:.
-
#write_mτ_head_skeleton(ɴ) ⇒ Object
Write the skeleton of the method header:.
-
#write_mτ_meat ⇒ Object
This consists of taking the atomic commands from @cmds array one by one and calling the command method to write a small piece of the program implied by the command.
-
#write_mτ_tail_skeleton ⇒ Object
Write the skeleton of the tail part of the method, consisting of the finisher line, returner line, and end statement itself.
-
#x ⇒ Object
‘x’ - 3rd from the end.
-
#y ⇒ Object
‘y’ - penultimate element.
-
#z ⇒ Object
‘z’ - last element.
-
#Z ⇒ Object
W: occupied by map with reverse order binary block X: Y:.
-
#¡« ⇒ Object
grab argument into the other pipe.
-
#¡» ⇒ Object
args.unshift from the other pipe.
-
#¡α ⇒ Object
When inverted exclamation mark ‘¡’ is used a prefix to the source selector, then rather then being pushed on the @argsrc stack, the new argument source replaces the topmost element of the stack.
- #¡β ⇒ Object
-
#¡δ ⇒ Object
def ¡γ; @argsrc.var! PRE[@rr].
- #¡ε ⇒ Object
- #¡ζ ⇒ Object
- #¡λ ⇒ Object
-
#¡π ⇒ Object
(also: #¡σ)
Small pi prefixed with inverted exclamation mark sets the ‘ref’ (default) grab mode for the top@argsrc element (naturally, turning off ‘shift’ or ‘dup’ mode).
-
#¡ρ ⇒ Object
Rho prefixed with inverted exclamation mark resets the @argsrc stack (to size 1, source: args_counted):.
- #¡ψ ⇒ Object
- #¡Ω ⇒ Object
- #¡ω ⇒ Object
-
#« ⇒ Object
unsh.
-
#² ⇒ Object
Next block arity 2 selection.
-
#» ⇒ Object
args.unshift from current pipe.
- #¿i ⇒ Object
-
#ß ⇒ Object
Other special character methods ********************************************************************.
-
#÷ ⇒ Object
binary / as /() unary method.
-
#ɪ ⇒ Object
memo: v is log.
-
#α ⇒ Object
α pushes the primary pipeline (0) on the @argsrc stack:.
-
#β ⇒ Object
β pushes the secondary pipeline (1) on the @argsrc stack:.
-
#γ ⇒ Object
γ refers to the successor pipe (SUCC[@rr]), but as there are only two pipes, it is always the other pipe.
-
#δ ⇒ Object
δ pushes the in-block pipeline delta on the @argsrc stack:.
-
#ε ⇒ Object
ε, ζ push block arguments epsilon, resp.
- #ζ ⇒ Object
-
#ι ⇒ Object
Iota decrements the @arg_count index.
-
#λ ⇒ Object
Lambda pushes onto the argument stack the default argument source, which is the argument list indexed with write-time @arg_count index:.
-
#π ⇒ Object
Small pi sets the ‘dup’ grab mode for the top @argsrc element:.
-
#ς ⇒ Object
Remaining Greek letters ********************************************************************.
-
#σ ⇒ Object
Small sigma sets the ‘shift’ grab mode for the top @argsrc element:.
-
#χ ⇒ Object
Controlling the pipes ********************************************************************.
-
#ψ ⇒ Object
ψ and ω respectively refer to the penultimate and last args element:.
- #ω ⇒ Object
-
#Ω ⇒ Object
Capital omega pushes onto the argument stack whole ‘args’ variable (whole argument list), with ‘shift’ mode turned on by default:.
-
#ᴇ ⇒ Object
Small caps ********************************************************************.
- #ᴊ ⇒ Object
-
#ᴍ ⇒ Object
Map in the other pipe.
-
#ᴘ ⇒ Object
make a pair.
-
#‹n ⇒ Object
double exclamation mark, not operator.
-
#‹‹ ⇒ Object
mnemonic: z is last.
-
#‹₊ ⇒ Object
Unary operators ********************************************************************.
-
#‹₋ ⇒ Object
subscript -, -@ method.
-
#‹﹗ ⇒ Object
small exclamation mark, !@ method.
-
#›A ⇒ Object
make a singleton array.
-
#›i ⇒ Object
def sU; end # def sV; end.
-
#›› ⇒ Object
mnemonic: precedes <<.
-
#⁇ ⇒ Object
As binary method:.
-
#⁈ ⇒ Object
Left part up to colon (included) as unary method:.
-
#⁉ ⇒ Object
Right part from colon (included) on as unary method:.
-
#ⁱ ⇒ Object
Superscript i.
-
#₀ ⇒ Object
Digit literals.
- #₁ ⇒ Object
- #₂ ⇒ Object
- #₃ ⇒ Object
- #₄ ⇒ Object
- #₅ ⇒ Object
- #₆ ⇒ Object
- #₇ ⇒ Object
- #₈ ⇒ Object
- #₉ ⇒ Object
-
#₊ ⇒ Object
binary + as +() unary method.
-
#₋ ⇒ Object
binary - as -() unary method.
-
#← ⇒ Object
Adaptive append:.
-
#→ ⇒ Object
Adaptive prepend:.
-
#∅ ⇒ Object
(also: #⊘, #ø)
Clear the current pipe (set to empty string):.
- #≤ ⇒ Object
- #≥ ⇒ Object
-
#● ⇒ Object
ji3 - compact.
-
#★ ⇒ Object
binary * as *() unary method.
-
#﹕ ⇒ Object
Colon literal:.
-
#﹕n ⇒ Object
Appending literals.
-
#﹕« ⇒ Object
literal << waiting for another literal.
-
#﹕» ⇒ Object
literal >> waiting for another literal.
-
#﹕÷ ⇒ Object
literal / waiting for another literal.
-
#﹕ʜ ⇒ Object
empty hash literal.
-
#﹕ς ⇒ Object
empty string literal.
-
#﹕ᴀ ⇒ Object
empty array literal.
-
#﹕₊ ⇒ Object
literal + waiting for another literal.
-
#﹕₋ ⇒ Object
literal - waiting for another literal.
-
#﹕★ ⇒ Object
literal * waiting for another literal.
-
#﹕﹤ ⇒ Object
literal < waiting for another literal.
-
#﹕﹪ ⇒ Object
literal % waiting for another literal.
-
#﹖ ⇒ Object
Question mark literal:.
-
#﹠ ⇒ Object
memo: x is log.
-
#﹡﹡ ⇒ Object
binary ** as **() unary method.
- #﹤ ⇒ Object
- #﹥ ⇒ Object
-
#﹦﹦ ⇒ Object
literal == waiting for another literal.
-
#﹦﹫ ⇒ Object
[]=.
-
#﹪ ⇒ Object
binary % as %() unary method.
-
#﹫ ⇒ Object
[].
Constructor Details
#initialize(command_ς) ⇒ PostfixMachine
PostfixMachine initialization
246 247 248 |
# File 'lib/pyper.rb', line 246 def initialize command_ |
Instance Method Details
#_ ⇒ Object
Explicit block closing.
782 783 784 785 786 787 788 |
# File 'lib/pyper.rb', line 782 def _ case @w # close block when in :block when :block then chain( close_block ) @w = :main if @rr.size == 1 unless @rr.empty? else raise "'_' (close block) used when not in block" end end |
#_r_ ⇒ Object
Active register reader
449 |
# File 'lib/pyper.rb', line 449 def _r_; @r end |
#a ⇒ Object
In Pyper, ‘car’ becomes ‘τaτ’, and applies to strings, too:
553 554 555 556 557 558 |
# File 'lib/pyper.rb', line 553 def a; pipe_2_variable; start "#@r =\n" + "if #@r.respond_to?( :first ) then #@r.first\n" + "elsif #@r.respond_to?( :[] ) then #@r[0]\n" + "else raise 'impossible to extract first element' end" start end |
#A ⇒ Object Also known as: Α
Latin capital letters ********************************************************************
929 |
# File 'lib/pyper.rb', line 929 def A; pipe_2_variable; start "Array(#@r)" end |
#alpha_touch ⇒ Object
register 0 (alpha) was required for computation
528 |
# File 'lib/pyper.rb', line 528 def alpha_touch; belay unless @alpha_touched or @beta_touched end |
#autoclose_open_blocks_and_return ⇒ Object
After we run out of atomic commands, it’s time to finalize the program by closing any blocks still left open. Metod #close_block called by this method actually produces the program string out of each block it closes, so this method actually returns the program string of whole newly written Pyper method.
400 401 402 403 |
# File 'lib/pyper.rb', line 400 def autoclose_open_blocks_and_return ( rslt = close_block; chain rslt; pipe_2_variable ) while @head.size > 1 return close_block end |
#b ⇒ Object
Extension of this idea: ‘b’ is 2nd, ‘c’ is 3rd:
561 562 563 564 565 566 |
# File 'lib/pyper.rb', line 561 def b; pipe_2_variable; start "#@r =\n" + "if #@r.respond_to?( :take ) then #@r.take(2)[1]\n" + "elsif #@r.respond_to?( :[] ) then #@r[1]\n" + "else raise 'unable to extract second collection element' end" start end |
#B ⇒ Object
eat block
931 |
# File 'lib/pyper.rb', line 931 def B; @take_block = true unless @take_block == :taken end |
#belay ⇒ Object
Store in active register, and continue in a new pipeline:
461 |
# File 'lib/pyper.rb', line 461 def belay; pipe_2_variable; start end |
#beta_autoinit ⇒ Object Also known as: beta_touch
register 1 (beta) was required for the computation
531 532 533 534 535 536 537 538 |
# File 'lib/pyper.rb', line 531 def beta_autoinit case @opts.op when 1 then s = "beta = self.dup rescue self" ( @main_opener.clear << s; @beta_touched = true ) unless @beta_touched when 2 then @main_opener.clear << "beta = self[1]" unless @beta_touched when -2 then @main_opener.clear << "beta = self[0]" unless @beta_touched else raise "wrong @opts[:op] value: #{@opts.op}" end end |
#bin_op(s, x = grab_arg) ⇒ Object
Write binary operator
467 |
# File 'lib/pyper.rb', line 467 def bin_op( s, x = grab_arg ); @pipe[-1] << " #{s} " << x end |
#binary_m(s, x = grab_arg, y = grab_arg) ⇒ Object
Chain binary method
481 482 |
# File 'lib/pyper.rb', line 481 def binary_m( s, x = grab_arg, y = grab_arg ) chain "#{s}( #{[x, y, maybe_block].compact.join(", ")} )" end |
#block(cmd) ⇒ Object
442 |
# File 'lib/pyper.rb', line 442 def block( cmd ); self.send( cmd ) end |
#block_2ary ⇒ Object
Next block will be written as binary:
521 |
# File 'lib/pyper.rb', line 521 def block_2ary; @block_arity = 2 end |
#block_2ary_swapped ⇒ Object
Next block will be writen as binary with swapped block arguments (delta = zeta; @argsrc.epsilon):
525 |
# File 'lib/pyper.rb', line 525 def block_2ary_swapped; @block_arity = -2 end |
#c ⇒ Object
568 569 570 571 572 573 |
# File 'lib/pyper.rb', line 568 def c; pipe_2_variable; start "#@r =\n" + "if #@r.respond_to?( :take ) then #@r.take(3)[2]\n" + "elsif #@r.respond_to?( :[] ) then #@r[2]\n" + "else raise 'unable to extract third collection element' end" start end |
#C ⇒ Object
explicit parenthesize
932 |
# File 'lib/pyper.rb', line 932 def C; paren end |
#chain(s) ⇒ Object
Chain (nullary) method string to the end of the pipe
453 |
# File 'lib/pyper.rb', line 453 def chain( s ); @pipe[-1] << ".#{s}" end |
#close_block ⇒ Object
Called to close a block, including the main def
406 407 408 409 410 |
# File 'lib/pyper.rb', line 406 def close_block unless @rr.empty? then @r = @rr.pop end # back with the register @pipe.pop; @opener.pop; @finisher.pop # pop the writing stack ( @head.pop + @tail.pop ).join # join head and tail end |
#d ⇒ Object
In Pyper ‘cdr’ becomes ‘τdτ’:
576 577 578 579 580 581 582 |
# File 'lib/pyper.rb', line 576 def d; pipe_2_variable; start "#@r =\n" + "if #@r.is_a?( Hash ) then Hash[ @r.drop(1) ]\n" + "elsif #@r.respond_to?( :drop ) then #@r.drop(1)\n" + "elsif #@r.respond_to?( :[] ) then #@r[1..-1]\n" + "else raise 'unable to #drop(1) or #[1..-1]' end" start end |
#D ⇒ Object
self.dup
933 |
# File 'lib/pyper.rb', line 933 def D; exe "#@r = #@r.dup" end |
#e ⇒ Object
‘e’, ‘f’ mean all but first 2, resp. 3 elements:
585 586 587 588 589 590 591 |
# File 'lib/pyper.rb', line 585 def e; pipe_2_variable; start "#@r =\n" + "if #@r.is_a?( Hash ) then Hash[ @r.drop(2) ]\n" + "elsif #@r.respond_to?( :drop ) then #@r.drop(2)\n" + "elsif #@r.respond_to?( :[] ) then #@r[2..-1]\n" + "else raise 'unable to #drop(2) or #[2..-1]' end" start end |
#E ⇒ Object
-> g
934 |
# File 'lib/pyper.rb', line 934 def E; exe "#{rSUCC} = #@r.dup" end |
#exe(s) ⇒ Object
pipe_2_variable, execute something else, and go back to @r
463 |
# File 'lib/pyper.rb', line 463 def exe( s ); pipe_2_variable; start s; start end |
#f ⇒ Object
592 593 594 595 596 597 598 |
# File 'lib/pyper.rb', line 592 def f; pipe_2_variable; start "#@r =\n" + "if #@r.is_a?( Hash ) then Hash[ @r.drop(3) ]\n" + "elsif #@r.respond_to?( :drop ) then #@r.drop(3)\n" + "elsif #@r.respond_to?( :[] ) then #@r[3..-1]\n" + "else raise 'unable to #drop(3) or #[3..-1]' end" start end |
#g ⇒ Object
Remaining latin letters ********************************************************************
903 |
# File 'lib/pyper.rb', line 903 def g; @am.r rSUCC( @rr[0] ) end |
#grab_arg ⇒ Object
Writer of argument grab strings.
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/pyper.rb', line 413 def grab_arg raise ArgumentError unless @argsrc.src.size == @argsrc.grab.size grab = case @argsrc.grab.last when :shift then ".shift" when :ref then "" when :dup then ".dup" else raise "unknown arg. grab method: #{@argsrc.grab.last}" end str = case @argsrc.src.last when :args_counted x = (@arg_count += 1) - 1; "args[#{x}]" + grab when :args then # now this is a bit difficult, cause case @argsrc.grab.last # it's necessary to discard the used when :shift then # args (shift #@arg_count): if @arg_count == 0 then "args.shift" else "(args.shift(#@arg_count); args.shift)" end when :ref then "args" else raise "unknown arg. grab method: #{@argsrc.grab.last}" end when :alpha then alpha_touch; 'alpha' + grab when :beta then beta_touch; 'beta' + grab when :delta, :epsilon, :zeta then @argsrc.src.last.to_s + grab when :psi then "args[-2]" + grab when :omega then "args[-1]" + grab else raise "unknown argument source: #{@argsrc.src.last}" end unless @argsrc.src.size <= 1 then @argsrc.src.pop; @argsrc.grab.pop end return str end |
#h ⇒ Object
set pipe <- whole args array
904 |
# File 'lib/pyper.rb', line 904 def h; set "args" end |
#H ⇒ Object
L
936 |
# File 'lib/pyper.rb', line 936 def H; pipe_2_variable; start "Hash[#@r.zip(#{rSUCC})]" end |
#initialize_writer_state ⇒ Object
Initialize method writing flags / state keepers
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/pyper.rb', line 302 def initialize_writer_state # set current pipeline to :alpha (pipeline 0) @r = :alpha # set current pipe stack to [@r] @rr = [@r] # (Pipeline stack is needed due to tha fact, that blocks are allowed # inside a Pyper method. At method write time, every time a block is # open, block pipeline symbol is pushed onto this stack.) # where are we? flag (whether in :main or :block) set to :main @w = :main # argument counter (for args dispensing to the individual methods) @arg_count = 0 # signal to pass the supplied block to the next method @take_block = false # arity flag for next block to be written, default is 1 @block_arity = 1 end |
#j ⇒ Object
i:
906 |
# File 'lib/pyper.rb', line 906 def j; chain "join" end |
#J ⇒ Object
binary join
937 |
# File 'lib/pyper.rb', line 937 def J; unary_m "join" end |
#m ⇒ Object
‘9’ - [-1st] (ie. an array with only the last collection element)
912 913 914 915 916 917 |
# File 'lib/pyper.rb', line 912 def m pipe_2_variable start "if #@r.is_a? String then #@r = #@r.each_char end\n" start nullary_m_with_block "map" end |
#M ⇒ Object
L:
939 940 941 942 943 944 |
# File 'lib/pyper.rb', line 939 def M # Map zipped this and other register using binary block block_2ary pipe_2_variable start "#@r.zip(#{rSUCC})" nullary_m_with_block "map" end |
#main(cmd) ⇒ Object
Execution methods (depending on @w at the moment)
441 |
# File 'lib/pyper.rb', line 441 def main( cmd ); self.send( cmd ) end |
#maybe_block ⇒ Object
Returns nothing or optional block, if flagged to do so
471 472 473 474 475 |
# File 'lib/pyper.rb', line 471 def maybe_block; case @take_block when true then @take_block = :taken; '&block' when nil, false, :taken then nil else raise "unexpected @take_block value" end end |
#nullary_m(s) ⇒ Object
Chain unary method
477 |
# File 'lib/pyper.rb', line 477 def nullary_m( s ); chain "#{s}(#{maybe_block})" end |
#nullary_m_with_block(str) ⇒ Object
Initiates writing a block method.
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/pyper.rb', line 484 def nullary_m_with_block( str ) # puts "in nullary_m_with_block, str = #{str}" # DEBUG if @take_block == true then nullary_m( str ) else # code a block @w = :block # change writing method belay # a must before block opening # push a new pipe, head and tail to the writing stack: @rr.empty? ? ( @rr = [@r] ) : ( @rr.push @r ) # store the register @r = :delta # a block runs in its own unswitchable register delta @pipe << String.new # push pipe # puts "@pipe is << #@pipe >>" # DEBUG @head << case @block_arity # push head when 0 then [ "#{str} { " ] when 1 then set "delta"; [ "#{str} { |epsilon|" ] when 2 then @argsrc.zeta; @argsrc.ref! set "delta"; [ "#{str} { |epsilon, zeta|" ] when -2 then @argsrc.epsilon; @argsrc.ref! set "delta"; [ "#{str} { |epsilon, zeta|" ] else raise "Unknown @block_arity: #@block_arity" end write "\n" opener = case @block_arity; when 0 then ""; when 1, 2 then "delta = epsilon" when -2 then "delta = zeta" end @opener << opener # push opener @block_arity = 1 # after use, set block arity flag back to default # puts "@pipe is << #@pipe >>" # DEBUG write opener; write "\n"; write @pipe.last finisher = String.new @finisher << finisher # push finisher @tail << [ "\n" ] # push tail @tail.last << finisher << "\n" << "}" # done end end |
#paren ⇒ Object
parethesize current pipe
465 |
# File 'lib/pyper.rb', line 465 def paren; @pipe[-1].prepend("( ") << " )" end |
#parse_command_string(arg) ⇒ Object
Command ς -> command ᴀ
251 252 253 254 255 256 257 258 259 260 |
# File 'lib/pyper.rb', line 251 def parse_command_string( arg ) # If supplied arg is an ᴀ, assume that it already is a command # sequence, and thus, no work at all is needed: return arg if arg.kind_of? Array # Otherwise, assume arg is a ς and split it using #each_char arg.to_s.each_char.with_object [] do |char, memo| # Handle prefix characters: ( PREFIX_CHARACTERS.include?(memo[-1]) ? memo[-1] : memo ) << char end end |
#pipe_2_variable ⇒ Object
Suck the pipe into the “memory” (active register)
455 |
# File 'lib/pyper.rb', line 455 def pipe_2_variable; @pipe[-1].prepend "#@r = "; eval "#{@r}_touched = true" end |
#R ⇒ Object
N: O: prefix character (ready to append literal) P: recursive piper method, begin Q: recursive piper method, end
951 952 953 954 |
# File 'lib/pyper.rb', line 951 def R # Reverse zip: Zip other and this register pipe_2_variable start "#{rSUCC}.zip(#@a)" end |
#rPRE(reg = @r) ⇒ Object
touch and return predecessor of a register, or @r by default
545 |
# File 'lib/pyper.rb', line 545 def rPRE reg=@r; send "#{PRE[reg]}_touch"; PRE[reg] end |
#rSUCC(reg = @r) ⇒ Object
touch and return successor of a register, or @r by default
542 |
# File 'lib/pyper.rb', line 542 def rSUCC reg=@r; send "#{SUCC[reg]}_touch"; SUCC[reg] end |
#set(s) ⇒ Object
Set the pipe to a value, discarding current contents
459 |
# File 'lib/pyper.rb', line 459 def set( s ); @pipe[-1].clear << s end |
#start(s = "#@r") ⇒ Object
Start a new pipe, on a new line. Without arguments, @r is used
457 |
# File 'lib/pyper.rb', line 457 def start( s = "#@r" ); write "\n"; @pipe[-1] = s; write @pipe.last end |
#U ⇒ Object
S: T: prefix character
957 |
# File 'lib/pyper.rb', line 957 def U; end |
#u ⇒ Object
‘u’ - all except last 3
646 647 648 649 650 651 652 |
# File 'lib/pyper.rb', line 646 def u; pipe_2_variable; start "#@r =\n" + "if #@r.is_a?( Hash ) then Hash[ @r.take( #@r.size - 3 ) ]\n" + "elsif #@r.respond_to?( :take ) then #@r.take( #@r.size - 3 )\n" + "elsif #@r.respond_to?( :[] ) then #@r[0...-3]\n" + "else raise 'unable to #drop(1) or #[1...-3]' end" start end |
#unary_m(s, x = grab_arg) ⇒ Object
478 479 |
# File 'lib/pyper.rb', line 478 def unary_m( s, x = grab_arg ) chain "#{s}( #{[x, maybe_block].compact.join(", ")} )" end |
#unary_op(s) ⇒ Object
Write unary operator
469 |
# File 'lib/pyper.rb', line 469 def unary_op( s ); paren; @pipe[-1].prepend s end |
#v ⇒ Object
‘v’ - all except last 2
637 638 639 640 641 642 643 |
# File 'lib/pyper.rb', line 637 def v; pipe_2_variable; start "#@r =\n" + "if #@r.is_a?( Hash ) then Hash[ @r.take( #@r.size - 2 ) ]\n" + "elsif #@r.respond_to?( :take ) then #@r.take( #@r.size - 2 )\n" + "elsif #@r.respond_to?( :[] ) then #@r[0...-2]\n" + "else raise 'unable to #drop(1) or #[1...-2]' end" start end |
#V ⇒ Object
unsh/prep self 2 reg (other changed)
958 |
# File 'lib/pyper.rb', line 958 def V; end |
#w ⇒ Object
‘w’ - all except last
628 629 630 631 632 633 634 |
# File 'lib/pyper.rb', line 628 def w; pipe_2_variable; start "#@r =\n" + "if #@r.is_a?( Hash ) then Hash[ @r.take( #@r.size - 1 ) ]\n" + "elsif #@r.respond_to?( :take ) then #@r.take( #@r.size - 1 )\n" + "elsif #@r.respond_to?( :[] ) then #@r[0...-1]\n" + "else raise 'unable to #drop(1) or #[1...-1]' end" start end |
#W ⇒ Object
<</app self 2 reg (other changed)
959 960 961 962 963 964 |
# File 'lib/pyper.rb', line 959 def W # Map zipped other and this register using binary block block_2ary # Mnemonic: W is inverted M pipe_2_variable start "#{rSUCC}.zip(#@r)" nullary_m_with_block "map" end |
#write(x) ⇒ Object
Append string to head
451 |
# File 'lib/pyper.rb', line 451 def write( x ); Array( x ).each {|e| @head[-1] << e } end |
#write_initial_pipeline ⇒ Object
Initialize the pipeline (@pipe)
341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/pyper.rb', line 341 def write_initial_pipeline @pipe = case @opts.op when 1 then [ "self" ] # use receiver (default) when 2 then # use alpha, beta = self[0], self[1] @alpha_touched = @beta_touched = true write "\n( alpha, beta = self[0], self[1]; alpha)\n" [ "alpha" ] # pipe 0 aka. primary pipe when -2 then # use alpha, beta = self[1], self[0] @alpha_touched = @beta_touched = true write "\n( alpha, beta = self[1], self[0]; alpha)\n" [ "alpha" ] # pipe 0 aka. primary pipe end # self compliance tested in the written method itself write "\n"; write @pipe[-1] # make @pipe part of @head end |
#write_mτ(ɴ, opts = {}) ⇒ Object
Algorithmically writes a Ruby mτ, whose name is given as 1st arg., and the options ꜧ expects 2 keys (:op and :ret) as follows:
op: when 1 (single pipe), makes no assumption about the receiver
When 2 (twin pipe), assumes the receiver is a size 2
ret: when 1 (single return value), returns current pipe only
when 2 (return both pipes), returns size 2
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/pyper.rb', line 277 def write_m |
#write_mτ_head_skeleton(ɴ) ⇒ Object
Write the skeleton of the method header:
326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/pyper.rb', line 326 def write_m |
#write_mτ_meat ⇒ Object
This consists of taking the atomic commands from @cmds array one by one and calling the command method to write a small piece of the program implied by the command.
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/pyper.rb', line 372 def write_m |
#write_mτ_tail_skeleton ⇒ Object
Write the skeleton of the tail part of the method, consisting of the finisher line, returner line, and end statement itself.
358 359 360 361 362 363 364 365 366 367 |
# File 'lib/pyper.rb', line 358 def write_m |
#x ⇒ Object
‘x’ - 3rd from the end
620 621 622 623 624 625 |
# File 'lib/pyper.rb', line 620 def x; pipe_2_variable; start "#@r =\n" + "if #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 3 ).first\n" + "elsif #@r.respond_to?( :[] ) then #@r[-3]\n" + "else raise 'unable to extract third-from-the-end element' end" start end |
#y ⇒ Object
‘y’ - penultimate element
612 613 614 615 616 617 |
# File 'lib/pyper.rb', line 612 def y; pipe_2_variable; start "#@r =\n" + "if #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 2 ).first\n" + "elsif #@r.respond_to?( :[] ) then #@r[-2]\n" + "else raise 'unable to extract second-from-the-end element' end" start end |
#z ⇒ Object
‘z’ - last element
604 605 606 607 608 609 |
# File 'lib/pyper.rb', line 604 def z; pipe_2_variable; start "#@r =\n" + "if #@r.respond_to?( :drop ) then #@r.drop( #@r.size - 1 ).first\n" + "elsif #@r.respond_to?( :[] ) then #@r[-1]\n" + "else raise 'unable to extract last element' end" start end |
#Z ⇒ Object
W: occupied by map with reverse order binary block X: Y:
969 970 971 972 |
# File 'lib/pyper.rb', line 969 def Z # Zip this and other register pipe_2_variable start "#@r.zip(#{rSUCC})" end |
#¡« ⇒ Object
grab argument into the other pipe
1046 1047 1048 1049 1050 |
# File 'lib/pyper.rb', line 1046 def |
#¡» ⇒ Object
args.unshift from the other pipe
1051 |
# File 'lib/pyper.rb', line 1051 def |
#¡α ⇒ Object
When inverted exclamation mark ‘¡’ is used a prefix to the source selector, then rather then being pushed on the @argsrc stack, the new argument source replaces the topmost element of the stack. When the stack size is 1, this has the additional effect of setting the given argument source as default, until another such change happens, or stack reset is invoked.
868 |
# File 'lib/pyper.rb', line 868 def |
#¡β ⇒ Object
869 |
# File 'lib/pyper.rb', line 869 def |
#¡ε ⇒ Object
872 |
# File 'lib/pyper.rb', line 872 def |
#¡ζ ⇒ Object
873 |
# File 'lib/pyper.rb', line 873 def |
#¡λ ⇒ Object
876 |
# File 'lib/pyper.rb', line 876 def |
#¡π ⇒ Object Also known as: ¡σ
Small pi prefixed with inverted exclamation mark sets the ‘ref’ (default) grab mode for the top@argsrc element (naturally, turning off ‘shift’ or ‘dup’ mode).
888 |
# File 'lib/pyper.rb', line 888 def |
#¡ρ ⇒ Object
Rho prefixed with inverted exclamation mark resets the @argsrc stack (to size 1, source: args_counted):
899 |
# File 'lib/pyper.rb', line 899 def |
#¡ψ ⇒ Object
874 |
# File 'lib/pyper.rb', line 874 def |
#¡Ω ⇒ Object
877 |
# File 'lib/pyper.rb', line 877 def |
#¡ω ⇒ Object
875 |
# File 'lib/pyper.rb', line 875 def |
#« ⇒ Object
unsh. r to self, << r to self And eight more with Array construct [a, b] def w; @am.args! end # arg. source = whole args array (shift! on) def x; pipe_2_variable; start( “##rSUCC.zip(#@r)” ) # zip other w. this
1044 |
# File 'lib/pyper.rb', line 1044 def |
#² ⇒ Object
Next block arity 2 selection
775 |
# File 'lib/pyper.rb', line 775 def |
#» ⇒ Object
args.unshift from current pipe
1045 |
# File 'lib/pyper.rb', line 1045 def |
#¿i ⇒ Object
1053 |
# File 'lib/pyper.rb', line 1053 def |
#ß ⇒ Object
Other special character methods ********************************************************************
1013 |
# File 'lib/pyper.rb', line 1013 def |
#÷ ⇒ Object
binary / as /() unary method
1066 |
# File 'lib/pyper.rb', line 1066 def |
#ɪ ⇒ Object
memo: v is log. or
981 |
# File 'lib/pyper.rb', line 981 def |
#α ⇒ Object
α pushes the primary pipeline (0) on the @argsrc stack:
831 |
# File 'lib/pyper.rb', line 831 def |
#β ⇒ Object
β pushes the secondary pipeline (1) on the @argsrc stack:
835 |
# File 'lib/pyper.rb', line 835 def |
#γ ⇒ Object
γ refers to the successor pipe (SUCC[@rr]), but as there are only two pipes, it is always the other pipe.
841 |
# File 'lib/pyper.rb', line 841 def |
#δ ⇒ Object
δ pushes the in-block pipeline delta on the @argsrc stack:
844 |
# File 'lib/pyper.rb', line 844 def |
#ε ⇒ Object
ε, ζ push block arguments epsilon, resp. zeta on the @argsrc stack:
847 |
# File 'lib/pyper.rb', line 847 def |
#ζ ⇒ Object
848 |
# File 'lib/pyper.rb', line 848 def |
#ι ⇒ Object
Iota decrements the @arg_count index. If iota is used once, it causes that same argument is used twice. If iota is used repeatedly, pointer goes further back in the arg. ᴀ.
895 |
# File 'lib/pyper.rb', line 895 def |
#λ ⇒ Object
Lambda pushes onto the argument stack the default argument source, which is the argument list indexed with write-time @arg_count index:
856 |
# File 'lib/pyper.rb', line 856 def |
#π ⇒ Object
Small pi sets the ‘dup’ grab mode for the top @argsrc element:
880 |
# File 'lib/pyper.rb', line 880 def |
#ς ⇒ Object
Remaining Greek letters ********************************************************************
976 |
# File 'lib/pyper.rb', line 976 def |
#σ ⇒ Object
Small sigma sets the ‘shift’ grab mode for the top @argsrc element:
883 |
# File 'lib/pyper.rb', line 883 def |
#χ ⇒ Object
Controlling the pipes ********************************************************************
792 793 794 795 |
# File 'lib/pyper.rb', line 792 def |
#ψ ⇒ Object
ψ and ω respectively refer to the penultimate and last args element:
851 |
# File 'lib/pyper.rb', line 851 def |
#ω ⇒ Object
852 |
# File 'lib/pyper.rb', line 852 def |
#Ω ⇒ Object
Capital omega pushes onto the argument stack whole ‘args’ variable (whole argument list), with ‘shift’ mode turned on by default:
860 |
# File 'lib/pyper.rb', line 860 def |
#ᴇ ⇒ Object
Small caps ********************************************************************
980 |
# File 'lib/pyper.rb', line 980 def |
#ᴊ ⇒ Object
982 |
# File 'lib/pyper.rb', line 982 def |
#ᴍ ⇒ Object
Map in the other pipe
983 984 985 986 987 |
# File 'lib/pyper.rb', line 983 def |
#ᴘ ⇒ Object
make a pair
988 989 990 991 992 |
# File 'lib/pyper.rb', line 988 def |
#‹n ⇒ Object
double exclamation mark, not operator
1060 |
# File 'lib/pyper.rb', line 1060 def |
#‹‹ ⇒ Object
mnemonic: z is last
1079 |
# File 'lib/pyper.rb', line 1079 def |
#‹₊ ⇒ Object
Unary operators ********************************************************************
1058 |
# File 'lib/pyper.rb', line 1058 def |
#‹₋ ⇒ Object
subscript -, -@ method
1059 |
# File 'lib/pyper.rb', line 1059 def |
#‹﹗ ⇒ Object
small exclamation mark, !@ method
1061 |
# File 'lib/pyper.rb', line 1061 def |
#›A ⇒ Object
make a singleton array
1103 |
# File 'lib/pyper.rb', line 1103 def |
#›i ⇒ Object
def sU; end # def sV; end
1102 |
# File 'lib/pyper.rb', line 1102 def |
#›› ⇒ Object
mnemonic: precedes <<
1078 |
# File 'lib/pyper.rb', line 1078 def |
#⁇ ⇒ Object
As binary method:
1004 |
# File 'lib/pyper.rb', line 1004 def |
#⁈ ⇒ Object
Left part up to colon (included) as unary method:
1006 |
# File 'lib/pyper.rb', line 1006 def |
#⁉ ⇒ Object
Right part from colon (included) on as unary method:
1008 |
# File 'lib/pyper.rb', line 1008 def |
#ⁱ ⇒ Object
Superscript i. Next block will have arity 2 and will be written with inverse parameter order.
779 |
# File 'lib/pyper.rb', line 779 def |
#₀ ⇒ Object
Digit literals
1124 |
# File 'lib/pyper.rb', line 1124 def |
#₁ ⇒ Object
1125 |
# File 'lib/pyper.rb', line 1125 def |
#₂ ⇒ Object
1126 |
# File 'lib/pyper.rb', line 1126 def |
#₃ ⇒ Object
1127 |
# File 'lib/pyper.rb', line 1127 def |
#₄ ⇒ Object
1128 |
# File 'lib/pyper.rb', line 1128 def |
#₅ ⇒ Object
1129 |
# File 'lib/pyper.rb', line 1129 def |
#₆ ⇒ Object
1130 |
# File 'lib/pyper.rb', line 1130 def |
#₇ ⇒ Object
1131 |
# File 'lib/pyper.rb', line 1131 def |
#₈ ⇒ Object
1132 |
# File 'lib/pyper.rb', line 1132 def |
#₉ ⇒ Object
1133 |
# File 'lib/pyper.rb', line 1133 def |
#₊ ⇒ Object
binary + as +() unary method
1063 |
# File 'lib/pyper.rb', line 1063 def |
#₋ ⇒ Object
binary - as -() unary method
1064 |
# File 'lib/pyper.rb', line 1064 def |
#← ⇒ Object
Adaptive append:
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 |
# File 'lib/pyper.rb', line 1028 def |
#→ ⇒ Object
Adaptive prepend:
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
# File 'lib/pyper.rb', line 1016 def |
#∅ ⇒ Object Also known as: ⊘, ø
Clear the current pipe (set to empty string):
1136 |
# File 'lib/pyper.rb', line 1136 def |
#≤ ⇒ Object
1072 |
# File 'lib/pyper.rb', line 1072 def |
#≥ ⇒ Object
1073 |
# File 'lib/pyper.rb', line 1073 def |
#● ⇒ Object
ji3 - compact
1054 |
# File 'lib/pyper.rb', line 1054 def |
#★ ⇒ Object
binary * as *() unary method
1065 |
# File 'lib/pyper.rb', line 1065 def |
#﹕ ⇒ Object
Colon literal:
1002 |
# File 'lib/pyper.rb', line 1002 def |
#﹕n ⇒ Object
Appending literals
1108 |
# File 'lib/pyper.rb', line 1108 def |
#﹕« ⇒ Object
literal << waiting for another literal
1120 |
# File 'lib/pyper.rb', line 1120 def |
#﹕» ⇒ Object
literal >> waiting for another literal
1121 |
# File 'lib/pyper.rb', line 1121 def |
#﹕÷ ⇒ Object
literal / waiting for another literal
1116 |
# File 'lib/pyper.rb', line 1116 def |
#﹕ʜ ⇒ Object
empty hash literal
1111 |
# File 'lib/pyper.rb', line 1111 def |
#﹕ς ⇒ Object
empty string literal
1109 |
# File 'lib/pyper.rb', line 1109 def |
#﹕ᴀ ⇒ Object
empty array literal
1110 |
# File 'lib/pyper.rb', line 1110 def |
#﹕₊ ⇒ Object
literal + waiting for another literal
1113 |
# File 'lib/pyper.rb', line 1113 def |
#﹕₋ ⇒ Object
literal - waiting for another literal
1114 |
# File 'lib/pyper.rb', line 1114 def |
#﹕★ ⇒ Object
literal * waiting for another literal
1115 |
# File 'lib/pyper.rb', line 1115 def |
#﹕﹤ ⇒ Object
literal < waiting for another literal
1119 |
# File 'lib/pyper.rb', line 1119 def |
#﹕﹪ ⇒ Object
literal % waiting for another literal
1117 |
# File 'lib/pyper.rb', line 1117 def |
#﹖ ⇒ Object
Question mark literal:
1000 |
# File 'lib/pyper.rb', line 1000 def |
#﹠ ⇒ Object
memo: x is log. mult.
1077 |
# File 'lib/pyper.rb', line 1077 def |
#﹡﹡ ⇒ Object
binary ** as **() unary method
1067 |
# File 'lib/pyper.rb', line 1067 def |
#﹤ ⇒ Object
1070 |
# File 'lib/pyper.rb', line 1070 def |
#﹥ ⇒ Object
1071 |
# File 'lib/pyper.rb', line 1071 def |
#﹦﹦ ⇒ Object
literal == waiting for another literal
1118 |
# File 'lib/pyper.rb', line 1118 def |
#﹦﹫ ⇒ Object
[]=
1076 |
# File 'lib/pyper.rb', line 1076 def |
#﹪ ⇒ Object
binary % as %() unary method
1068 |
# File 'lib/pyper.rb', line 1068 def |
#﹫ ⇒ Object
1075 |
# File 'lib/pyper.rb', line 1075 def |