Class: CodeCdrInstruction

Inherits:
Instruction show all
Defined in:
lib/instructions/code/code_cdr.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Instruction

#context

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

#cleanupObject



29
30
31
# File 'lib/instructions/code/code_cdr.rb', line 29

def cleanup
  pushes :code, @result
end

#deriveObject



20
21
22
23
24
25
26
27
28
# File 'lib/instructions/code/code_cdr.rb', line 20

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

#preconditions?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/instructions/code/code_cdr.rb', line 14

def preconditions?
  needs :code, 1
end

#setupObject



17
18
19
# File 'lib/instructions/code/code_cdr.rb', line 17

def setup
  @arg = @context.pop_value(:code)
end