Class: MiniKraken::Rela::DefRelation

Inherits:
Core::Relation show all
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

Attributes included from Core::Entry

#name, #suffix

Attributes inherited from Core::Specification

#arity, #name

Instance Method Summary collapse

Methods included from Core::Entry

#i_name, #init_name

Methods inherited from Core::Specification

#check_arity, #inspect, #variadic?

Constructor Details

#initialize(aName, anExpression, theFormals) ⇒ DefRelation

Returns a new instance of DefRelation.

Parameters:

  • aName (String)

    name of def relation

  • anExpression (Term)
  • theFormals (Array<String>)


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

#expressionTerm (readonly)

Returns Expression to be fulfilled and parametrized with formals.

Returns:

  • (Term)

    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

#formalsArray<FormalArg> (readonly)

Returns formal arguments of this DefRelation.

Returns:

  • (Array<FormalArg>)

    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.

Parameters:

  • actuals (Array<Term>)

    A two-elements array

  • ctx (Context)

    A Context object

Returns:

  • (Fiber<Outcome>)

    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