Sha256: 9f6f10b8429f8cbeeb4ba762a25f1d5aa372ec8d3032a9539406e0eb29a148b9

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require_relative '../core/term'
require_relative '../core/freshness'

module MiniKraken
  # This module packages the composite term classes.
  # These hold one or more MiniKanren objects.
  module Composite
    # An composite term is an Minikraken term that can be
    # decomposed into simpler MiniKraken data value(s).
    class CompositeTerm < Core::Term
      # Abstract method (to override). Return the child terms.
      # @return [Array<Term>]
      def children
        raise NotImplementedError, 'This method must re-defined in subclass(es).'
      end

      # A composite term is fresh when all its members are nil or all non-nil members
      # are all fresh
      # A composite term is bound when it is not fresh and not ground
      # A composite term is a ground term when all its non-nil members are ground.
      # @param _env [Vocabulary]
      # @return [Freshness]
      def freshness(_env)
         env.freshness_composite(self)
      end

      # @param env [Environment]
      # @return [Boolean]
      def fresh?(env)
        env.fresh_value?(self)
      end

      # A composite is ground if all its children are ground
      def ground?(anEnv)
        children.all? do |child|
          child.nil? || child.ground?(anEnv)
        end
      end
    end # class
  end # module
end # module

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mini_kraken-0.2.04 lib/mini_kraken/composite/composite_term.rb