This function takes an unquantified KIF sentence (the syntactic thing, an expression) and returns the set of variables occuring freely in the sentence. This is only defined for unquantified sentences, and only handles individual variables (not sequence variables).
(=> (Variables-In-Sentence ?S ?Vset) (= ?Vset (Cond ((Logsent ?S) (Apply Union (Map Variables-In-Sentence (Rest ?S)))) ((Relsent ?S) (Apply Union (Variables-In-Term (Rest ?S)))) ((Logconst ?S) (Setof)) ((Quantsent ?S) Bottom))))