Skip to content

Commit

Permalink
add flat=False to process step by step
Browse files Browse the repository at this point in the history
  • Loading branch information
noskill committed Oct 30, 2023
1 parent 1120b3a commit d5b8104
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions python/hyperon/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,24 @@ def run(self, program, flat=False):
"""Runs the program"""
parser = SExprParser(program)
results = hp.metta_run(self.cmetta, parser.cparser)
return self.process_results(flat, results)

def process_results(self, flat, results):
if flat:
return [Atom._from_catom(catom) for result in results for catom in result]
else:
return [[Atom._from_catom(catom) for catom in result] for result in results]

def run_step_by_step(self, program):
def run_step_by_step(self, program, flat=False):
"""Runs program step by step, yielding state and result"""
state = RunnerState(self, program)
state.run_step()
results = state.current_results()
yield state, results
yield state, self.process_results(flat, results)
while not state.is_complete():
state.run_step()
results = state.current_results()
yield state, results
yield state, self.process_results(flat, results)


class Environment:
Expand Down

0 comments on commit d5b8104

Please sign in to comment.