Put all of the students into a list and then you can count the number
of students in the list:
(defrule create-list
(not (student-list $?))
(student ?name)
=>
(assert (student-list ?name)))
(defrule add-student
?f <- (student-list $?students)
(student ?name)
(test (not (member$ ?name ?students)))
=>
(retract ?f)
(assert (student-list ?name ?students)))
(defrule more-than-2-students
(declare (salience -10))
(student-list $?students)
(test (> (length$ ?students) 2))
=>
(printout t "3 or more students" crlf))