Class: Keisan::AST::List
Instance Attribute Summary
Attributes inherited from Parent
#children
Instance Method Summary
collapse
Methods inherited from Parent
#==, #deep_dup, #freeze, #replace, #traverse, #unbound_functions, #unbound_variables
Methods inherited from Node
#!, #%, #&, #*, #**, #+, #+@, #-, #-@, #/, #<, #<<, #<=, #>, #>=, #>>, #^, #and, #coerce, #contains_a?, #deep_dup, #differentiate, #differentiated, #equal, #evaluate_assignments, #evaluated, #false?, #not_equal, #or, #replace, #replaced, #simplified, #to_node, #traverse, #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
13
|
# File 'lib/keisan/ast/list.rb', line 8
def evaluate(context = nil)
return self if frozen?
context ||= Context.new
@children = children.map {|child| child.is_a?(Cell) ? child : child.evaluate(context)}
self
end
|
#simplify(context = nil) ⇒ Object
15
16
17
|
# File 'lib/keisan/ast/list.rb', line 15
def simplify(context = nil)
evaluate(context)
end
|
#to_a ⇒ Object
28
29
30
|
# File 'lib/keisan/ast/list.rb', line 28
def to_a
@children.map(&:value)
end
|
#to_cell ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/keisan/ast/list.rb', line 32
def to_cell
AST::Cell.new(
self.class.new(
@children.map(&:to_cell)
)
)
end
|
#to_s ⇒ Object
24
25
26
|
# File 'lib/keisan/ast/list.rb', line 24
def to_s
"[#{children.map(&:to_s).join(',')}]"
end
|
#value(context = nil) ⇒ Object
19
20
21
22
|
# File 'lib/keisan/ast/list.rb', line 19
def value(context = nil)
context ||= Context.new
children.map {|child| child.value(context)}
end
|