How is Lisp's read-eval-print loop different than Python's?

后端 未结 4 1949
长情又很酷
长情又很酷 2021-01-30 15:52

I\'ve encounter a following statement by Richard Stallman:

\'When you start a Lisp system, it enters a read-eval-print loop. Most other languages have not

4条回答
  •  -上瘾入骨i
    2021-01-30 16:30

    Python's interactive mode differs from Python's "read code from file" mode in several, small, crucial ways, probably inherent in the textual representation of the language. Python is also not homoiconic, something that makes me call it "interactive mode" rather than "read-eval-print loop". That aside, I'd say that it is more a difference of grade than a difference in kind.

    Now, something tahtactually comes close to "difference in kind", in a Python code file, you can easily insert blank lines:

    def foo(n):
      m = n + 1
    
      return m
    

    If you try to paste the identical code into the interpreter, it will consider the function to be "closed" and complain that you have a naked return statement at the wrong indentation. This does not happen in (Common) Lisp.

    Furthermore, there are some rather handy convenience variables in Common Lisp (CL) that are not available (at least as far as I know) in Python. Both CL and Python have "value of last expression" (* in CL, _ in Python), but CL also has ** (value of expression before last) and *** (the value of the one before that) and +, ++ and +++ (the expressions themselves). CL also doesn't distinguish between expressions and statements (in essence, everything is an expression) and all of that does help build a much richer REPL experience.

    As I said at the beginning, it is more a difference in grade than difference in kind. But had the gap been only a smidgen wider between them, it would probably be a difference in kind, as well.

提交回复
热议问题