This must be a faq: Is there a function that returns a lst of all variables in an ex? Or, what's wrong with the following (which leaves symbols empty)? class CollectSymbols_Visitor : public visitor, public symbol::visitor { public: lst symbols; CollectSymbols_Visitor() {} void visit (const symbol& x) { for (lst::const_iterator i = symbols.begin(); i != symbols.end(); i++) if (*i == x) return; symbols.append(x); } }; int main() { symbol x("x"); ex e = x - 2; CollectSymbols_Visitor collector; e.accept (collector); const lst& sym = collector.symbols; cout << sym << endl; }
It should have been traverse() instead of accept(). I expected that this would change visiting order only and cannot explain why it did not work with accept(). ralf
participants (2)
-
Ralf Stephan
-
varg@thsun1.jinr.ru