simple about pattern matching

Alex Rice alrice at ARCplanning.com
Wed Jul 30 12:44:01 EDT 2003


I'm sure this is an elementary one, but I've skimmed through all my 
CLIPS docs & still am confused. A "See p.xxx of the Reference Manual" 
would be great...

This rule checks for duplicate spaces. (does not check for duplicate 
facts- these spaces may differ in other slots)

(defrule warn-duplicate-space
   (calc-space (scenario ?scenario)
	      (section ?section)
	      (subsection ?subsection)
	      (space-name ?name)
	      (space-label ?label))
   (calc-space (scenario ?scenario)
	      (section ?section)
	      (subsection ?subsection)
	      (space-name ?name)
	      (space-label ?label))
   =>
   (printout wtrace "*** duplicate calc-space " ?subsection "/" ?name)
)

FIRE   33 warn-duplicate-space: f-159,f-159
*** duplicate calc-space objects-storage/pallets-small

I get trace output showing that the same fact address is matching two 
different CEs in the LHS.  I thought that was impossible, but it's 
apparently not. OK why did I think that? Actually I know you can't 
answer that. If I rewrite the rule to text like this, then it works as 
I expected. Any better way to match this?

(defrule warn-duplicate-space
   ?f1 <- (calc-space (scenario ?scenario)
		     (section ?section)
		     (subsection ?subsection)
		     (space-name ?name)
		     (space-label ?label))
   ?f2 <- (calc-space (scenario ?scenario)
		     (section ?section)
		     (subsection ?subsection)
		     (space-name ?name)
		     (space-label ?label))
   (test (neq ?f1 ?f2))
   =>
   (printout wtrace "*** duplicate calc-space " ?subsection "/" ?name)
)

Thanks,

Alex Rice, Software Developer
Architectural Research Consultants, Inc.
http://ARCplanning.com




More information about the use-livecode mailing list