Class: Keisan::AST::List

Inherits:
Parent show all
Defined in:
lib/keisan/ast/list.rb

Instance Attribute Summary

Attributes inherited from Parent

#children

Instance Method Summary collapse

Methods inherited from Parent

#==, #deep_dup, #freeze, #replace, #unbound_functions, #unbound_variables

Methods inherited from Node

#!, #%, #&, #*, #**, #+, #+@, #-, #-@, #/, #<, #<=, #>, #>=, #^, #and, #coerce, #deep_dup, #differentiate, #equal, #evaluate_assignments, #evaluated, #false?, #not_equal, #or, #replace, #simplified, #to_node, #true?, #unbound_functions, #unbound_variables, #well_defined?, #|, #~

Constructor Details

#initialize(children = []) ⇒ List

Returns a new instance of List.



4
5
6
# File 'lib/keisan/ast/list.rb', line 4

def initialize(children = [])
  super(children)
end

Instance Method Details

#evaluate(context = nil) ⇒ Object



8
9
10
11
12
# File 'lib/keisan/ast/list.rb', line 8

def evaluate(context = nil)
  context ||= Context.new
  @children = children.map {|child| child.is_a?(Cell) ? child : child.evaluate(context)}
  self
end

#simplify(context = nil) ⇒ Object



14
15
16
# File 'lib/keisan/ast/list.rb', line 14

def simplify(context = nil)
  evaluate(context)
end

#to_aObject



27
28
29
# File 'lib/keisan/ast/list.rb', line 27

def to_a
  @children.map(&:value)
end

#to_cellObject



31
32
33
34
35
36
37
# File 'lib/keisan/ast/list.rb', line 31

def to_cell
  AST::Cell.new(
    self.class.new(
      @children.map(&:to_cell)
    )
  )
end

#to_sObject



23
24
25
# File 'lib/keisan/ast/list.rb', line 23

def to_s
  "[#{children.map(&:to_s).join(',')}]"
end

#value(context = nil) ⇒ Object



18
19
20
21
# File 'lib/keisan/ast/list.rb', line 18

def value(context = nil)
  context ||= Context.new
  children.map {|child| child.value(context)}
end