Пример #1
0
void Formula::copy(TermList *frm, TermList *to)
{
	int sz = frm->getList()->size();
	for (int i = 0; i < sz; i++) {
		Term *t = frm->getList()->at(i);
		if (t->getType() == Term::CONS) {
			to->addTerm(t);
		}
		else if (t->getType() == Term::VAR) {
			if (t->isFree()) {
				to->addTerm(t);
			}
			else {
				Term *x = new Term(*t);
				to->addTerm(x);
			}
		}
		else {
			TermList *list = new TermList();
			this->copy(t->getTermList(), list);
			Term *f = new Term(t->getName(), list);
			to->addTerm(f);
		}
	}
}
Пример #2
0
void TermList::getFreeVarList(TermList *list)
{
	int sz = this->list->size();
	for (int i = 0; i < sz; i++) {
		Term *t = this->list->at(i);
		if (t->getType() == Term::VAR && t->isFree()) {
			list->addTerm(t);
		}
		else if (t->getType() == Term::FUNC) {
			t->getTermList()->getFreeVarList(list);
		}
	}
}