Sha256: e5f11943fb66db024eb22b14cdd71baf94c827c211c107f50775d0447e99643f
Contents?: true
Size: 848 Bytes
Versions: 3
Compression:
Stored size: 848 Bytes
Contents
# pops the top item from the +:code+ stack; # implements a equivalent to Lisp's +cdr+ function, treating Nudge blocks as lists: # # If the +:code+ value has at least 2 points (meaning it's a block with at least 1 element), # the new code value is this block with its first element deleted; otherwise, the result is # an empty block. # # *needs:* 1 +:code+ # # *pushes:* 1 +:code+ # class CodeCdrInstruction < Instruction def preconditions? needs :code, 1 end def setup @arg = @context.pop_value(:code) end def derive tree = NudgeProgram.new(@arg) if tree.linked_code.kind_of?(CodeblockPoint) && (tree.points > 1) new_tree = tree.delete_point(2) else new_tree = CodeblockPoint.new([]) end @result = ValuePoint.new("code", new_tree.blueprint) end def cleanup pushes :code, @result end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nudge-0.2.9 | lib/instructions/code/code_cdr.rb |
nudge-0.2.8 | lib/instructions/code/code_cdr.rb |
nudge-0.2.7 | lib/instructions/code/code_cdr.rb |