module Rubylog::CompoundTerm

Attributes

rubylog_variables[RW]

should return a copy with rubylog_deep_dereference called for sub-terms def rubylog_deep_dereference self.class.new attr1.rubylog_deep_dereference end

Public Instance Methods

rubylog_match_variables() click to toggle source

returns a copy of the term, with variables with the same name meade same objects. Don’t care variables are not matched.

# File lib/rubylog/compound_term.rb, line 5
def rubylog_match_variables 
  vars = []; vars_by_name = {}

  rubylog_clone do |subterm|
    case subterm
    when Rubylog::Variable
      var = subterm

      if var.dont_care?
        # duplicate don't care variables
        var.dup
      else
        # see if a var with that name already exists
        new_var = vars_by_name[var.name]
        if new_var
          # append guards
          new_var.guards = new_var.guards + var.guards
          new_var
        else
          # create and add new var
          new_var = var.dup
          vars << new_var
          vars_by_name[var.name] = new_var
          new_var
        end
      end

    when Rubylog::CompoundTerm
      # save rubylog variables
      subterm.rubylog_variables=vars
      subterm
    else
      subterm
    end
  end
end