Skip to content

Commit

Permalink
Fix infinite loop
Browse files Browse the repository at this point in the history
Infinite loop happens in case expression with variable operation is
interpreted. In such case it is returned without modification from query
and starts being interpreted again. For example in (cdr-atom ($A $B $C))
  • Loading branch information
vsbogd committed Feb 8, 2024
1 parent 181a330 commit 93e0b9f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/src/metta/interpreter2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ fn query<'a, T: SpaceRef<'a>>(space: T, prev: Option<Rc<RefCell<Stack>>>, atom:
// TODO: This is a hotfix. Better way of doing this is adding
// a function which modifies minimal MeTTa interpreter code
// in order to skip such evaluations in metta-call function.
return finished_result(atom, bindings, prev);
return finished_result(return_not_reducible(), bindings, prev)
}
let var_x = &VariableAtom::new("X").make_unique();
let query = Atom::expr([EQUAL_SYMBOL, atom.clone(), Atom::Variable(var_x.clone())]);
Expand Down Expand Up @@ -916,7 +916,7 @@ mod tests {
#[cfg(feature = "variable_operation")]
assert_eq!(result, vec![metta_atom("A")]);
#[cfg(not(feature = "variable_operation"))]
assert_eq!(result, vec![expr!(a "A" b)]);
assert_eq!(result, vec![NOT_REDUCIBLE_SYMBOL]);
}


Expand Down

0 comments on commit 93e0b9f

Please sign in to comment.