Sha256: cb3021f11725db37b49373486984cc83548a5f67843cd520972b510c102fad18

Contents?: true

Size: 957 Bytes

Versions: 4

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

require_relative '../core/environment'
require_relative '../core/variable'

module MiniKraken
  module Glue
    # (fresh (x) (== 'pea q))
    # Introduces the new variable 'x'
    # Takes a list of names and a goal-like object
    # Must respond to message attain(aPublisher, vars) and must return an Outcome
    class FreshEnv < Core::Environment
      # @return [Goal]
      attr_reader :goal

      # @param theNames [Array<String>]
      # @param aGoal [Goal]
      def initialize(theNames, aGoal)
        super()
        @goal = aGoal
        theNames.each { |nm| add_var(Core::Variable.new(nm)) }
      end

      # Attempt to achieve the goal given this environment
      # @param aParent [Environment]
      # @return [Fiber<Outcome>] A Fiber object that will generate the results.
      def attain(aParent)
        self.parent = aParent
        goal.attain(self)
      end
    end # class
  end # module
end # module

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mini_kraken-0.1.08 lib/mini_kraken/glue/fresh_env.rb
mini_kraken-0.1.07 lib/mini_kraken/glue/fresh_env.rb
mini_kraken-0.1.06 lib/mini_kraken/glue/fresh_env.rb
mini_kraken-0.1.05 lib/mini_kraken/glue/fresh_env.rb