Lisp的read-eval-print循环与Python的不同之处如何? [英] How is Lisp's read-eval-print loop different than Python's?

查看:245
本文介绍了Lisp的read-eval-print循环与Python的不同之处如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Richard Stallman的以下声明


'当您启动一个Lisp系统时,它会进入一个读取评估打印循环。大多数其他语言没有什么可比性,与eval没有什么可比性,也没有与打印相媲美的东西。缺陷有多大? '


现在,我在Lisp中做了很少的编程,但是我在Python中编写了大量的代码,最近有一点二郎。我的印象是,这些语言也提供了read-eval-print循环,但是Stallman不同意(至少是关于Python):

lockquote

'I skimmed人们告诉我这与Python的基本相似之后,Python的文档。我的结论是,事实并非如此。当你启动Lisp时,它会'读取','eval'和'print',所有这些在Python中都是缺失的。'

Lisp和Python的read-eval-print循环之间有真正的技术区别吗?你可以举一些Lisp REPL变得简单而且很难在Python中完成的事情吗?

为解决方案

为了支持Stallman的立场,Python在以下方面与典型的Lisp系统不同:


  • 读取Lisp中的函数读取一个S表达式,它表示一个任意的数据结构,它可以被视为数据,或者被视为代码。在Python中最接近的东西是读取一个单独的字符串,如果你希望它意味着什么,你将不得不解析自己。

  • 在Lisp中,eval 函数可以执行任何Lisp代码。 Python中的 eval 函数仅评估表达式,并且需要 exec 语句来运行语句。但是,这两个工作都以Python文本代码的形式工作,你必须跳过一堆箍来评估Python AST。 code> print 函数在Lisp中写出一个与 read 接受的形式完全相同的S表达式。在Python中输入 print 打印出您尝试打印的数据所定义的内容,这当然不总是可逆的。 / ul>

    Stallman的陈述有点不真诚,因为很明显Python 确实有命名的函数完全是 eval print ,但他们做了与他期望的不同的事情(和低劣的事情)。



    在我看来,Python does 有一些与Lisp类似的方面,我可以理解为什么人们可能会建议Stallman查看Python。然而,正如 Paul Graham在什么是不同的Lisp中有所不同,任何包含Lisp所有功能的编程语言都必须 be Lisp。


    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 nothing comparable to read, nothing comparable to eval, and nothing comparable to print. What gaping deficiencies! '

    Now, I did very little programming in Lisp, but I've wrote considerable amount of code in Python and recently a little in Erlang. My impression was that these languages also offer read-eval-print loop, but Stallman disagrees (at least about Python):

    'I skimmed documentation of Python after people told me it was fundamentally similar to Lisp. My conclusion is that that is not so. When you start Lisp, it does 'read', 'eval', and 'print', all of which are missing in Python.'

    Is there really a fundamental technical difference between Lisp's and Python's read-eval-print loops? Can you give examples of things that Lisp REPL makes easy and that are difficult to do in Python?

    解决方案

    In support of Stallman's position, Python does not do the same thing as typical Lisp systems in the following areas:

    • The read function in Lisp reads an S-expression, which represents an arbitrary data structure that can either be treated as data, or evaluated as code. The closest thing in Python reads a single string, which you would have to parse yourself if you want it to mean anything.

    • The eval function in Lisp can execute any Lisp code. The eval function in Python evaluates only expressions, and needs the exec statement to run statements. But both these work with Python source code represented as text, and you have to jump through a bunch of hoops to "eval" a Python AST.

    • The print function in Lisp writes out an S-expression in exactly the same form that read accepts. print in Python prints out something defined by the data you're trying to print, which is certainly not always reversible.

    Stallman's statement is a bit disingenuous, because clearly Python does have functions named exactly eval and print, but they do something different (and inferior) to what he expects.

    In my opinion, Python does have some aspects similar to Lisp, and I can understand why people might have recommended that Stallman look into Python. However, as Paul Graham argues in What Made Lisp Different, any programming language that includes all the capabilities of Lisp, must also be Lisp.

    这篇关于Lisp的read-eval-print循环与Python的不同之处如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆