Class: MiniKraken::Core::ParametrizedTerm

Inherits:
Term show all
Defined in:
lib/mini_kraken/core/parametrized_term.rb

Overview

A specialization of Term class for objects that take arguments.

Direct Known Subclasses

Goal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(theSpecification, theArgs) ⇒ ParametrizedTerm

Constructor.

Parameters:

  • theSpecification (Specification)

    The callable object.

  • theArgs (Array<Term>)

    The actual aguments



19
20
21
22
23
24
# File 'lib/mini_kraken/core/parametrized_term.rb', line 19

def initialize(theSpecification, theArgs)
  super()
  @specification = validated_specification(theSpecification)
  args = specification.check_arity(theArgs)
  @actuals = validated_actuals(args)
end

Instance Attribute Details

#actualsArray<Term> (readonly)

Returns The actual aguments of the goal.

Returns:

  • (Array<Term>)

    The actual aguments of the goal



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

def actuals
  @actuals
end

#specificationSpecification (readonly)

Returns The specification that must be invoked with arguments.

Returns:

  • (Specification)

    The specification that must be invoked with arguments.



11
12
13
# File 'lib/mini_kraken/core/parametrized_term.rb', line 11

def specification
  @specification
end

Instance Method Details

#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:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mini_kraken/core/parametrized_term.rb', line 35

def dup_cond(substitutions)
  duplicate = dup

  updated_actuals = actuals.map do |e|
    if e.is_a?(Array)
      e.map {|item| item.dup_cond(substitutions) }
    else
      e.dup_cond(substitutions) 
    end
  end
  duplicate.actuals.concat(updated_actuals)

  duplicate
end

#initialize_copy(orig) ⇒ Object



26
27
28
29
# File 'lib/mini_kraken/core/parametrized_term.rb', line 26

def initialize_copy(orig)
  @specification = orig.specification
  @actuals = []
end