Use the fact set query functions (section 12.9.12 in the Basic Programming Guide):
CLIPS>
(deftemplate cell
(slot x)
(slot y)
(slot type (allowed-values urban rural lake hill gate border)))
CLIPS>
(deftemplate inspect
(slot x)
(slot y))
CLIPS>
(deffacts example
(inspect (x 3) (y 3))
(cell (type urban) (x 1) (y 1))
(cell (type rural) (x 2) (y 3))
(cell (type lake) (x 4) (y 4))
(cell (type border) (x 4) (y 4))
(cell (type hill) (x 3) (y 5))
(cell (type gate) (x 3) (y 3)))
CLIPS>
(defrule inspect
; Changed to inspect so the example does
; not fire this rule for every cell
(inspect (x ?xval) (y ?yval))
=>
(do-for-all-facts ((?c cell))
(and (<= (- ?xval 1) ?c:x (+ ?xval 1))
(<= (- ?yval 1) ?c:y (+ ?yval 1)))
(printout t ?c:type " " ?c:x " " ?c:y crlf)))
CLIPS> (reset)
CLIPS> (run)
rural 2 3
lake 4 4
border 4 4
gate 3 3
CLIPS>