Class: MiniKraken::Rela::DefRelation
- Inherits:
-
Core::Relation
- Object
- Core::Specification
- Core::Relation
- MiniKraken::Rela::DefRelation
- Includes:
- Core::Entry
- Defined in:
- lib/mini_kraken/rela/def_relation.rb
Overview
A user-defined relation with:
-
a user-defined name,
-
a ordered list of generic formal arguments, and;
-
a goal template expression.
Instance Attribute Summary collapse
-
#expression ⇒ Term
readonly
Expression to be fulfilled and parametrized with formals.
-
#formals ⇒ Array<FormalArg>
readonly
Formal arguments of this DefRelation.
Attributes included from Core::Entry
Attributes inherited from Core::Specification
Instance Method Summary collapse
-
#initialize(aName, anExpression, theFormals) ⇒ DefRelation
constructor
A new instance of DefRelation.
-
#solver_for(actuals, ctx) ⇒ Fiber<Outcome>
A Fiber(-like) instance that yields Outcomes.
Methods included from Core::Entry
Methods inherited from Core::Specification
#check_arity, #inspect, #variadic?
Constructor Details
#initialize(aName, anExpression, theFormals) ⇒ DefRelation
Returns a new instance of DefRelation.
25 26 27 28 29 30 31 32 |
# File 'lib/mini_kraken/rela/def_relation.rb', line 25 def initialize(aName, anExpression, theFormals) @formals = validated_formals(theFormals) formal_vars = formals.map { |nm| Core::LogVarRef.new(nm) } raw_expression = validated_expression(anExpression) @expression = replace_expression(raw_expression, theFormals, formal_vars) super(aName, formals.size) freeze end |
Instance Attribute Details
#expression ⇒ Term (readonly)
Returns Expression to be fulfilled and parametrized with formals.
20 21 22 |
# File 'lib/mini_kraken/rela/def_relation.rb', line 20 def expression @expression end |
#formals ⇒ Array<FormalArg> (readonly)
Returns formal arguments of this DefRelation.
17 18 19 |
# File 'lib/mini_kraken/rela/def_relation.rb', line 17 def formals @formals end |
Instance Method Details
#solver_for(actuals, ctx) ⇒ Fiber<Outcome>
Returns A Fiber(-like) instance that yields Outcomes.
37 38 39 40 |
# File 'lib/mini_kraken/rela/def_relation.rb', line 37 def solver_for(actuals, ctx) actual_expr = replace_expression(expression, formals, actuals) actual_expr.achieve(ctx) end |