Class: CodeCarInstruction
- Inherits:
-
Instruction
- Object
- Instruction
- CodeCarInstruction
- Defined in:
- lib/instructions/code/code_car.rb
Overview
pops the top item from the :code
stack; implements a equivalent to Lisp’s car
function, treating Nudge blocks as lists:
If the :code
value has at least two points (meaning it’s a block with at least 1 element), the new code value is the blueprint of the first element of that block; otherwise the “new” code is the original item’s blueprint. A new :code
ValuePoint is created with this value and pushed.
needs: 1 :code
pushes: 1 :code
Instance Attribute Summary
Attributes inherited from Instruction
Instance Method Summary collapse
Methods inherited from Instruction
all_instructions, #go, inherited, #initialize, #needs, #pushes, to_nudgecode
Constructor Details
This class inherits a constructor from Instruction
Instance Method Details
#cleanup ⇒ Object
32 33 34 |
# File 'lib/instructions/code/code_car.rb', line 32 def cleanup pushes :code, @result end |
#derive ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/instructions/code/code_car.rb', line 22 def derive tree = NudgeProgram.new(@arg) if tree.linked_code.kind_of?(CodeblockPoint) && (tree.points > 2) new_tree = tree[1].contents[0] else new_tree = tree end @result = ValuePoint.new("code", new_tree.blueprint) end |
#preconditions? ⇒ Boolean
14 15 16 |
# File 'lib/instructions/code/code_car.rb', line 14 def preconditions? needs :code, 1 end |
#setup ⇒ Object
18 19 20 |
# File 'lib/instructions/code/code_car.rb', line 18 def setup @arg = @context.pop_value(:code) end |