int LispObject::Equal(LispObject& aOther) { // next line handles the fact that either one is a string if (String() != aOther.String()) return 0; // return false //So, no strings. LispPtr *iter1 = SubList(); LispPtr *iter2 = aOther.SubList(); assert(!!iter1 && !!iter2); // check all elements in sublist while (!!(*iter1) && !!(*iter2)) { if (! (*iter1)->Equal(*(*iter2) )) return 0; iter1 = &(*iter1)->Nixed(); iter2 = &(*iter2)->Nixed(); } //One list longer than the other? if (!(*iter1) && !(*iter2)) return 1; return 0; }
const YacasParamMatcherBase* YacasPatternPredicateBase::MakeParamMatcher(LispEnvironment& aEnvironment, LispObject* aPattern) { if (!aPattern) return nullptr; if (aPattern->Number(aEnvironment.Precision())) return new MatchNumber(aPattern->Number(aEnvironment.Precision())); // Deal with atoms if (aPattern->String()) return new MatchAtom(aPattern->String()); // Else it must be a sublist if (aPattern->SubList()) { // See if it is a variable template: LispPtr* sublist = aPattern->SubList(); assert(sublist); LispInt num = InternalListLength(*sublist); // variable matcher here... if (num>1) { LispObject* head = (*sublist); if (head->String() == aEnvironment.HashTable().LookUp("_")) { LispObject* second = head->Nixed(); if (second->String()) { LispInt index = LookUp(second->String()); // Make a predicate for the type, if needed if (num>2) { LispPtr third; LispObject* predicate = second->Nixed(); if (predicate->SubList()) { InternalFlatCopy(third, *predicate->SubList()); } else { third = (second->Nixed()->Copy()); } LispObject* last = third; while (!!last->Nixed()) last = last->Nixed(); last->Nixed() = LispAtom::New(aEnvironment, *second->String()); iPredicates.push_back(LispPtr(LispSubList::New(third))); } return new MatchVariable(index); } } } std::vector<const YacasParamMatcherBase*> matchers; matchers.reserve(num); LispIterator iter(*sublist); for (LispInt i = 0; i < num; ++i, ++iter) { matchers.push_back(MakeParamMatcher(aEnvironment,iter.getObj())); assert(matchers[i]); } return new MatchSubList(std::move(matchers)); } return nullptr; }