class Keisan::AST::Parent

Attributes

children[R]

Public Class Methods

new(children = []) click to toggle source
# File lib/keisan/ast/parent.rb, line 6
def initialize(children = [])
  children = Array(children).map do |child|
    child.is_a?(Cell) ? child : child.to_node
  end
  raise Exceptions::InternalError.new unless children.is_a?(Array)
  @children = children
end

Public Instance Methods

==(other) click to toggle source
# File lib/keisan/ast/parent.rb, line 43
def ==(other)
  return false unless self.class == other.class

  children.size == other.children.size && children.map.with_index {|_,i|
    children[i] == other.children[i]
  }.all? {|bool|
    bool == true
  }
end
deep_dup() click to toggle source
# File lib/keisan/ast/parent.rb, line 53
def deep_dup
  dupped = dup
  dupped.instance_variable_set(
    :@children,
    dupped.children.map(&:deep_dup)
  )
  dupped
end
evaluate(context = nil) click to toggle source
# File lib/keisan/ast/parent.rb, line 62
def evaluate(context = nil)
  context ||= Context.new
  @children = children.map {|child| child.evaluate(context)}
  self
end
freeze() click to toggle source
Calls superclass method
# File lib/keisan/ast/parent.rb, line 38
def freeze
  children.each(&:freeze)
  super
end
is_constant?() click to toggle source
# File lib/keisan/ast/parent.rb, line 79
def is_constant?
  @children.all?(&:is_constant?)
end
replace(variable, replacement) click to toggle source
# File lib/keisan/ast/parent.rb, line 74
def replace(variable, replacement)
  @children = children.map {|child| child.replace(variable, replacement)}
  self
end
simplify(context = nil) click to toggle source
# File lib/keisan/ast/parent.rb, line 68
def simplify(context = nil)
  context ||= Context.new
  @children = @children.map {|child| child.simplify(context)}
  self
end
traverse(&block) click to toggle source
Calls superclass method Keisan::AST::Node#traverse
# File lib/keisan/ast/parent.rb, line 28
def traverse(&block)
  value = super(&block)
  return value if value
  children.each do |child|
    value = child.traverse(&block)
    return value if value
  end
  false
end
unbound_functions(context = nil) click to toggle source
# File lib/keisan/ast/parent.rb, line 21
def unbound_functions(context = nil)
  context ||= Context.new
  children.inject(Set.new) do |fns, child|
    fns | child.unbound_functions(context)
  end
end
unbound_variables(context = nil) click to toggle source
# File lib/keisan/ast/parent.rb, line 14
def unbound_variables(context = nil)
  context ||= Context.new
  children.inject(Set.new) do |vars, child|
    vars | child.unbound_variables(context)
  end
end