forked from patham9/metta-nars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.py
46 lines (42 loc) · 1.48 KB
/
repl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Author: Douglas Miles
from hyperon.runner import MeTTa
import sys
import readline
import os
runner = MeTTa()
class REPL:
def __init__(self):
self.history = []
def main_loop(self):
while True:
try:
# Use the input function to get user input
line = input("metta> ")
# If the line isn't empty, evaluate it
if line:
self.history.append(line)
result = runner.run(line)
if result is not None:
print(result)
# Handle Ctrl+C to exit
except KeyboardInterrupt:
print("\nCtrl-C Exiting...")
sys.exit(3)
# Handle Ctrl+D to exit
except EOFError:
print("\n Ctrl-D EOF...")
sys.exit(0)
# If there's an error, print it
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
repl = REPL()
readline.add_history("!(AddBeliefEvent ((({ garfield }) --> cat) (1.0 0.9)))")
readline.add_history("!(AddBeliefEvent (((cat * sky) --> like) (1.0 0.9)))")
readline.add_history("!(AddBeliefEvent ((sky --> ([ blue ])) (1.0 0.9)))")
readline.add_history("!(EternalQuestion ((({ garfield }) * ([ blue ])) --> like))")
os.chdir("./src/")
os.system("sh build.sh")
with open("NARS.metta") as f:
runner.run(f.read())
repl.main_loop()