Class: MiniKraken::Core::AnyValue

Inherits:
Object
  • Object
show all
Defined in:
lib/mini_kraken/core/any_value.rb

Overview

When MiniKraken successfully finds a solution but cannot associate a definite value to one or more logical variable(s), then it is useful to “assign” such unbound variable a placeholder that stands for any possible value. Following the practice of the “Reasoned Scheme” book, we associate a rank number to such a placeholder in order to distinguish arbitrary values from independent variables.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aRank) ⇒ AnyValue

Returns a new instance of AnyValue.

Parameters:

  • aRank (Integer)

    The rank of the variable that must reified.



17
18
19
# File 'lib/mini_kraken/core/any_value.rb', line 17

def initialize(aRank)
  @rank = aRank
end

Instance Attribute Details

#rankInteger (readonly)

The rank number helps to differentiate independent variables.

Returns:

  • (Integer)


14
15
16
# File 'lib/mini_kraken/core/any_value.rb', line 14

def rank
  @rank
end

Instance Method Details

#==(other) ⇒ Boolean

Compare with another instance.

Parameters:

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'lib/mini_kraken/core/any_value.rb', line 24

def ==(other)
  if other.is_a?(AnyValue)
    rank == other.rank
  elsif other.is_a?(Integer)
    rank == other
  elsif other.id2name =~ /_\d+/
    rank == other.id2name.sub(/_/, '').to_i
  end
end

#pinned?(_ctx) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/mini_kraken/core/any_value.rb', line 40

def pinned?(_ctx)
  false
end

#quote(_ctx) ⇒ AnyValue

Returns:



45
46
47
# File 'lib/mini_kraken/core/any_value.rb', line 45

def quote(_ctx)
  self
end

#to_sObject

Use same text representation as in “Reasoned Schemer” book. return [String]



36
37
38
# File 'lib/mini_kraken/core/any_value.rb', line 36

def to_s
  "_#{rank}"
end