Permalink
Browse files

bug fixes for the main engine. excluded InitialFact from list of facts

  • Loading branch information...
1 parent 65de6dc commit 4206d3181e826b838e0e68b6ff952d7bfd5ded51 @jkutner jkutner committed Jun 2, 2011
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/core/engine.rb
View
12 lib/core/engine.rb
@@ -211,9 +211,9 @@ def initialize(wm=WorkingMemory.new,cr=RulebyConflictResolver.new)
end
def facts
- @working_memory.facts.collect{|f| f.object}
+ @working_memory.facts.collect{|f| f.object}.select{|f| !f.is_a?(InitialFact)}
end
-
+
# This method id called to add a new fact to working memory
def assert(object,&block)
@wm_altered = true
@@ -224,6 +224,10 @@ def assert(object,&block)
def retract(object,&block)
@wm_altered = true
fact_helper(object,:minus,&block)
+
+ # I have mixed feelings about doing this...
+ assert InitialFact.new if facts.empty?
+ object
end
# This method is called to alter an existing fact. It is essentially a
@@ -267,11 +271,11 @@ def match(agenda=nil, used_agenda=[])
end
def errors
- @root.errors
+ @root.nil? ? [] : @root.errors
end
def clear_errors
- @root.clear_errors
+ @root.clear_errors if @root
end
def print

0 comments on commit 4206d31

Please sign in to comment.