MCPcopy
hub / github.com/fluentpython/example-code-2e / repl

Function repl

18-with-match/lispy/original/lispy.py:107–118  ·  view source on GitHub ↗

A prompt-read-eval-print loop.

(prompt='lispy> ', inport=InPort(sys.stdin), out=sys.stdout)

Source from the content-addressed store, hash-verified

105 repl(None, InPort(open(filename)), None)
106
107def repl(prompt='lispy> ', inport=InPort(sys.stdin), out=sys.stdout):
108 "A prompt-read-eval-print loop."
109 sys.stderr.write("Lispy version 2.0\n")
110 while True:
111 try:
112 if prompt: sys.stderr.write(prompt)
113 x = parse(inport)
114 if x is eof_object: return
115 val = eval(x)
116 if val is not None and out: print(to_string(val), file=out)
117 except Exception as e:
118 print('%s: %s' % (type(e).__name__, e))
119
120################ Environment class
121

Callers 2

loadFunction · 0.70
lispy.pyFile · 0.70

Calls 4

InPortClass · 0.85
to_stringFunction · 0.85
parseFunction · 0.70
evalFunction · 0.70

Tested by

no test coverage detected