always print variable bindings before names
@@ -831,11 +831,7 @@ fn check_for_seen(&mut self, iter: &mut HCPreOrderIterator) -> Option<Addr> {
}
match self.heap_locs.get(&addr).cloned() {
- Some(var) => {
- if !self.printed_vars.contains(&addr) {
- self.printed_vars.insert(addr);
- return iter.next();
- } else {
+ Some(var) if addr.is_ref() => {
iter.stack().pop();
push_space_if_amb!(self, &var, {
@@ -844,8 +840,7 @@ fn check_for_seen(&mut self, iter: &mut HCPreOrderIterator) -> Option<Addr> {
return None;
}
- }
- None => {
+ var_opt => {
let offset = match functor_location(&addr) {
Some(offset) => offset,
None => {
@@ -858,17 +853,32 @@ fn check_for_seen(&mut self, iter: &mut HCPreOrderIterator) -> Option<Addr> {
if reps > 0 {
self.cyclic_terms.insert(addr, reps - 1);
} else {
+ match var_opt {
+ Some(var) => {
+ push_space_if_amb!(self, &var, {
+ self.append_str(&var);
+ });
+
+ iter.stack().pop();
+ }
+ None => {
push_space_if_amb!(self, "...", {
self.append_str("...");
});
iter.stack().pop();
self.cyclic_terms.insert(addr, 2);
+ }
+ }
return None;
}
} else if self.machine_st.is_cyclic_term(addr.clone()) {
+ if var_opt.is_some() {
+ self.cyclic_terms.insert(addr, 0);
+ } else {
self.cyclic_terms.insert(addr, 2);
+ }
} else {
self.record_children_as_non_cyclic(&addr);
self.non_cyclic_terms.insert(offset);
