class Array
In Porolog
, Arrays are the equivalent of lists.
Public Instance Methods
@param other [Object] the Object
which is to be the tail @return [Array] an Array
with the Object
being the head and the other Object
being the tail.
# File lib/porolog/core_ext.rb, line 146 def /(other) if other.is_a?(Porolog::Variable) || other.is_a?(Symbol) self + [Porolog::Tail.new(other)] else self + [*other] end end
Removes Porolog
processing objects. @return [Array] the values of its elements with variables replaced by nil and Tails replaced by UNKNOWN_TAIL.
# File lib/porolog/core_ext.rb, line 125 def clean value.map{|element| if element.is_a?(Array) element.clean elsif element.is_a?(Porolog::Tail) Porolog::UNKNOWN_TAIL elsif element.is_a?(Porolog::Variable) nil else element.value end } end
@return [Porolog::Goal] the goal that is most likely to be the goal for this array.
# File lib/porolog/core_ext.rb, line 184 def goal map{|element| element.goal if element.respond_to?(:goal) }.flatten.find{|goal| goal.is_a?(Porolog::Goal) } end
@param head_size [Integer] specifies the size of the head @return [Object] the head of the Array
# File lib/porolog/core_ext.rb, line 156 def head(head_size = 1) if head_size == 1 if first == Porolog::UNKNOWN_TAIL nil else first end else self[0...head_size] end end
@param head_size [Integer] specifies the size of the head @return [Object] the tail of the Array
# File lib/porolog/core_ext.rb, line 170 def tail(head_size = 1) if last == Porolog::UNKNOWN_TAIL [*self[head_size..-2], Porolog::UNKNOWN_TAIL] else [*self[head_size..-1]] end end
@return [Symbol] the type of the object (for an Array
, should be :array)
# File lib/porolog/core_ext.rb, line 140 def type :array end
@return [Array] the values of its elements.
# File lib/porolog/core_ext.rb, line 92 def value(visited = []) return self if visited.include?(self) visited = visited + [self] flat_map{|element| if element.is_a?(Porolog::Tail) tail = element.value(visited) if tail.is_a?(Array) tail elsif tail.is_a?(Porolog::Variable) || tail.is_a?(Porolog::Value) tail = tail.value(visited) if tail.is_a?(Array) tail elsif tail.is_a?(Porolog::Variable) || tail.is_a?(Porolog::Value) tail = tail.goal.variablise(tail.value(visited)) if tail.is_a?(Array) tail else [element] end else [element] end else [element] end else [element.value(visited)] end } end
@return [Array] embedded variables.
# File lib/porolog/core_ext.rb, line 87 def variables map(&:variables).flatten end