Skip to content

Commit f120c1b

Browse files
authored
Merge pull request #1023 from vsbogd/fix-bool
Fix bool
2 parents 714a061 + d7c977e commit f120c1b

File tree

4 files changed

+12
-37
lines changed

4 files changed

+12
-37
lines changed

hyperon-atom/src/lib.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -656,32 +656,6 @@ pub fn match_by_string_equality(this: &str, other: &Atom) -> matcher::MatchResul
656656
}
657657
}
658658

659-
/// A more thorough version of [match_by_equality], which will attempt the match in reverse order
660-
/// if the `other` atom doesn't wrap the same type as `this`
661-
pub fn match_by_bidirectional_equality<T>(this: &T, other: &Atom) -> matcher::MatchResultIter
662-
where T: 'static + PartialEq + Clone + Grounded + Debug
663-
{
664-
log::trace!("match_by_bidirectional_equality: this: {:?}, other: {}", this, other);
665-
if let Some(other_obj) = other.as_gnd::<T>() {
666-
match this == other_obj {
667-
true => Box::new(std::iter::once(matcher::Bindings::new())),
668-
false => Box::new(std::iter::empty()),
669-
}
670-
} else {
671-
let temp_atom = Atom::gnd(this.clone());
672-
match other {
673-
Atom::Grounded(gnd) => {
674-
if let Some(matchable) = gnd.as_grounded().as_match() {
675-
matchable.match_(&temp_atom)
676-
} else {
677-
Box::new(std::iter::empty())
678-
}
679-
},
680-
_ => Box::new(std::iter::empty()),
681-
}
682-
}
683-
}
684-
685659
/// Alias for the list of traits required for the standard Rust types to be
686660
/// automatically wrapped into [GroundedAtom]. It is implemented automatically
687661
/// when type implements `'static + PartialEq + Clone + Debug`. No need

lib/src/metta/runner/bool.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,11 @@ impl Grounded for Bool {
4343
ATOM_TYPE_BOOL
4444
}
4545

46-
fn as_match(&self) -> Option<&dyn CustomMatch> {
47-
Some(self)
48-
}
49-
5046
fn serialize(&self, serializer: &mut dyn serial::Serializer) -> serial::Result {
5147
serializer.serialize_bool(self.0)
5248
}
5349
}
5450

55-
impl CustomMatch for Bool {
56-
fn match_(&self, other: &Atom) -> matcher::MatchResultIter {
57-
match_by_bidirectional_equality(self, other)
58-
}
59-
}
60-
6151
#[derive(Default)]
6252
struct BoolSerializer {
6353
value: Option<Bool>,

python/hyperon/exts/py_ops/pyop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
@register_tokens
55
def arithm_types():
66
return {
7-
r"True|False": lambda token: ValueAtom(bool(token), 'Bool'),
7+
r"True|False": lambda token: ValueAtom(token == "True", 'Bool'),
88
r"[-+]?\d+": lambda token: ValueAtom(int(token), 'Number'),
99
r"[-+]?\d+\.\d+": lambda token: ValueAtom(float(token), 'Number'),
1010
r"[-+]?\d+(\.\d+)?[eE][-+]?\d+": lambda token: ValueAtom(float(token), 'Number'),

python/tests/test_modules.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,16 @@ def test_py_ops(self):
4848
result = runner.run('!(* "a" 4)')
4949
self.assertEqual(result[0][0], ValueAtom('aaaa'))
5050

51+
def test_bool(self):
52+
"""
53+
Tests that boolean value is properly parsed by py_ops
54+
"""
55+
runner = MeTTa(env_builder=Environment.custom_env())
56+
runner.run("!(import! &self py_ops)")
57+
result = runner.run('!(id False)')
58+
self.assertEqual(result[0][0], ValueAtom(False))
59+
result = runner.run('!(id True)')
60+
self.assertEqual(result[0][0], ValueAtom(True))
61+
5162
if __name__ == "__main__":
5263
unittest.main()

0 commit comments

Comments
 (0)