2 ms·
Python 3 for comparison: while True: print(eval(input(">>> ")))
by Macha 8y ago
Python 3 for comparison:
while True:
print(eval(input(">>> ")))
- frostoov 8y agoNot really: ovov@ovov ~> cat repl.py while True: print(eval(input(">>> "))) ovov@ovov ~> python3 repl.py >>> x = 1 Traceback (most recent call last): File "repl.py", line 2, in <module> print(eval(input(">>> "))) File "<string>", line 1 x = 1 ^ SyntaxError: invalid syntax
- reikonomusha 8y agoThis is a fundamentally different function that works with strings and not symbolic data structures.
- kbp 8y ago`input` isn't READ, it's READ-LINE. READ reads one Lisp form, even if it's more than one line, and even if there are more than one on one line. Python's `eval` also isn't sufficient here. For example, you cannot enter that loop you wrote at the prompt it provides when you run it, even if you write it on one line. You could use `exec`, but then everything would print as `None`. There's the larger point about forms vs strings and printing readably and such, but this doesn't even provide the same basic functionality that a Python programmer would expect from a REPL.