Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matching in binding maps should be done on structures if possible #276

Open
Leo-Nogismus opened this issue Sep 25, 2023 · 0 comments
Open

Comments

@Leo-Nogismus
Copy link
Collaborator

In binding_map.cpp, when calling intersect() or contains() on StructureValue s and AtomValues, we only do exact matching of atoms, or, in the case of floats, the match is calculated with Utils::Equal(). This should be changed to allow the matching of objects, especially for StructureValues. This would allow for user-defined equals-operators, allowing for more complex matching. For example, we could define angle as its own class and use user-defined equals-operators to check for 2*pi angle difference. Or use more complex structures for direct matching.

The code would need to be changed to utilize user-defined operators in the following three code segments.

AERA/r_exec/binding_map.cpp

Lines 204 to 213 in f774c52

bool AtomValue::contains(const Atom a) const {
if (atom_ == a)
return true;
if (atom_.isFloat() && a.isFloat())
return Utils::Equal(atom_.asFloat(), a.asFloat());
return false;
}

AERA/r_exec/binding_map.cpp

Lines 293 to 313 in f774c52

bool StructureValue::contains(const Atom *s) const {
if (structure_->code(0) != s[0])
return false;
if (structure_->code(0).getDescriptor() == Atom::TIMESTAMP)
return Utils::Synchronous(Utils::GetTimestamp(&structure_->code(0)), Utils::GetTimestamp(s));
for (uint16 i = 1; i < structure_->code_size(); ++i) {
Atom a = structure_->code(i);
Atom _a = s[i];
if (a == _a)
continue;
if (a.isFloat() && _a.isFloat())
return Utils::Equal(a.asFloat(), _a.asFloat());
return false;
}
return true;
}

AERA/r_exec/binding_map.cpp

Lines 720 to 729 in f774c52

bool BindingMap::match_atom(Atom o_atom, Atom p_atom) {
if (p_atom == o_atom)
return true;
if (p_atom.isFloat() && o_atom.isFloat())
return Utils::Equal(o_atom.asFloat(), p_atom.asFloat());
return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant