Class: MiniKraken::Atomic::AtomicTerm

Inherits:
Core::Term show all
Defined in:
lib/mini_kraken/atomic/atomic_term.rb

Overview

An atomic term is an elementary MiniKraken term, a data value that cannot be decomposed into simpler MiniKraken term(s). Typically, an atomic term encapsulates a Ruby primitive data object. MiniKraken treats atomic terms as immutable objects.

Direct Known Subclasses

KBoolean, KInteger, KString, KSymbol

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aValue) ⇒ AtomicTerm

Initialize an atomic term with the given data object.

Parameters:

  • aValue (Object)

    Ruby representation of MiniKraken data value



21
22
23
24
25
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 21

def initialize(aValue)
  super()
  @value = aValue
  @value.freeze
end

Instance Attribute Details

#valueObject (readonly)

Returns Internal representation of a MiniKraken data value.

Returns:

  • (Object)

    Internal representation of a MiniKraken data value.



17
18
19
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 17

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean

Data equality testing

Parameters:

Returns:

  • (Boolean)


64
65
66
67
68
69
70
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 64

def ==(other)
  if other.respond_to?(:value)
    value == other.value
  else
    value == other
  end
end

#dependencies(_ctx) ⇒ Set

Return the list of variable (i_names) that this term depends on. For atomic terms, there is no such dependencies.

Parameters:

Returns:

  • (Set)

    an empty set



83
84
85
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 83

def dependencies(_ctx)
  Set.new
end

#dup_cond(_substitutions) ⇒ Term

Make a copy of self with all the variable reference being replaced by the corresponding value in the Hash.

Parameters:

  • _substitutions (Hash {String => Term})

Returns:

  • (Term)


91
92
93
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 91

def dup_cond(_substitutions)
  dup
end

#eql?(other) ⇒ Boolean

Type and data equality testing

Parameters:

Returns:

  • (Boolean)


75
76
77
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 75

def eql?(other)
  (self.class == other.class) && value.eql?(other.value)
end

#floating?(_ctx) ⇒ FalseClass

An atomic term has a definite value, therefore it is not floating.

Parameters:

  • _ctx (Context)

Returns:

  • (FalseClass)


37
38
39
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 37

def floating?(_ctx)
  false
end

#pinned?(_ctx) ⇒ TrueClass

An atomic term is a pinned term: by definition, it has a definite value.

Parameters:

  • _ctx (Context)

Returns:

  • (TrueClass)


45
46
47
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 45

def pinned?(_ctx)
  true
end

#quote(_ctx) ⇒ AtomicTerm

Treat this object as a data value.

Returns:



57
58
59
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 57

def quote(_ctx)
  self
end

#to_sString

Return a String representation of the atomic term

Returns:

  • (String)


51
52
53
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 51

def to_s
  value.to_s
end

#unbound?(_ctx) ⇒ FalseClass

An atomic term, by definition is bound to a definite value.

Parameters:

  • _ctx (Context)

Returns:

  • (FalseClass)


30
31
32
# File 'lib/mini_kraken/atomic/atomic_term.rb', line 30

def unbound?(_ctx)
  false
end