Class: Skeem::SkmCompoundDatum

Inherits:
SkmElement
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/skeem/skm_compound_datum.rb

Overview

Abstract class.

Direct Known Subclasses

SkmVector

Instance Attribute Summary collapse

Attributes inherited from SkmElement

#position

Instance Method Summary collapse

Methods inherited from SkmElement

#boolean?, #bound!, #callable?, #char?, #complex?, #done!, #inspect, #integer?, #list?, #null?, #number?, #pair?, #procedure?, #rational?, #real?, #skm_eq?, #string?, #symbol?, #vector?

Constructor Details

#initialize(theMembers) ⇒ SkmCompoundDatum

Returns a new instance of SkmCompoundDatum.



17
18
19
20
# File 'lib/skeem/skm_compound_datum.rb', line 17

def initialize(theMembers)
  super(nil)
  @members = theMembers.nil? ? [] : theMembers
end

Instance Attribute Details

#membersObject Also known as: children, to_a

Returns the value of attribute members.



11
12
13
# File 'lib/skeem/skm_compound_datum.rb', line 11

def members
  @members
end

Instance Method Details

#==(other) ⇒ Object Also known as: skm_equal?



22
23
24
25
26
27
28
29
30
31
# File 'lib/skeem/skm_compound_datum.rb', line 22

def ==(other)
  return true if equal?(other)

  case other
    when SkmCompoundDatum
      self.class == other.class && members == other.members
    when Array
      members == other
  end
end

#accept(aVisitor) ⇒ Object

Part of the 'visitee' role in Visitor design pattern.

Parameters:



64
65
66
# File 'lib/skeem/skm_compound_datum.rb', line 64

def accept(aVisitor)
  aVisitor.visit_compound_datum(self)
end

#evaluate(aRuntime) ⇒ Object



41
42
43
44
# File 'lib/skeem/skm_compound_datum.rb', line 41

def evaluate(aRuntime)
  members_eval = members.map { |elem| elem.evaluate(aRuntime) }
  self.class.new(members_eval)
end

#quasiquote(aRuntime) ⇒ Object

Return this object un-evaluated. Reminder: As terminals are atomic, there is no need to launch a visitor.

Parameters:



49
50
51
52
# File 'lib/skeem/skm_compound_datum.rb', line 49

def quasiquote(aRuntime)
  quasi_members = members.map { |elem| elem.quasiquote(aRuntime) }
  self.class.new(quasi_members)
end

#quoted!Object



54
55
56
# File 'lib/skeem/skm_compound_datum.rb', line 54

def quoted!
  members.each(&:quoted!)
end

#unquoted!Object



58
59
60
# File 'lib/skeem/skm_compound_datum.rb', line 58

def unquoted!
  members.each(&:unquoted!)
end

#verbatim?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/skeem/skm_compound_datum.rb', line 36

def verbatim?
  found = members.find_index { |elem| !elem.verbatim? }
  found ? false : true
end