是什么让 Python 不是函数式编程语言?

fra*_*lin 3 python programming-languages functional-programming first-class-functions

Python 变量是鸭子类型的,可变的,它的函数可以编写为具有副作用。(换句话说,它有很多非函数式编程特性。)

但是,它也具有一流的功能,但它不是函数式编程语言。所以我想,即使它不属于该范式,编程语言也可以具有功能方面(或另一种语言范式的方面),这一定是真的。究竟是什么让 Python不是函数式编程语言?是测试它是否具有单一特征或多个事物的测试?(如果是前者,使 Python 无法运行的单个方面或使 Haskell 具有功能的单个方面是什么?)

Car*_*ate 5

Python被认为是函数式的;如果您可以信任维基百科:

范式多范式:函数式、命令式、面向对象、反射式

强调我的。这是来自摘要侧栏。

And it should be noted that the "FP-ness" of a language isn't binary, it's on a continuum. Python doesn't have built in support for efficient manipulation of immutable structures as far as I know. That's one large knock against it, as immutability can be considered a strong aspect of FP. It also doesn't support tail-call optimization, which can be a problem when dealing with recursive solutions. As you mentioned though, it does have first-class functions, and built-in support for some idioms, such as map/comprehensions/generator expressions, reduce and lazy processing of data.

If you want to deal exclusively with functional programming idioms, Python may not be the best choice. That alone doesn't exclude it from being considered a functional language though.

  • 几乎所有语言都是多范式的。 (3认同)