“功能是第一类值”这究竟意味着什么? [英] "functions are first class values" what does this exactly mean?

查看:125
本文介绍了“功能是第一类值”这究竟意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以用一些很好的例子来清楚地解释它。在解释函数式编程的时候,我在Scala中遇到了这个语句。 解释方案

它意味着函数可以传递给相同的函数作为整数,序列等的方式。

一个例子(虽然不是Scala):

 >>> def add2(x):
... return x + 2
...
>>> map(add2,[1,2,3])
[3,4,5]


Could somebody clearly explain it with some good example. I came across this statement in Scala, when explaining about the functional programming.

解决方案

It means that functions can be passed around the same way as integers, sequences, etc.

An example (although not Scala):

>>> def add2(x):
...   return x + 2
... 
>>> map(add2, [1, 2, 3])
[3, 4, 5]

这篇关于“功能是第一类值”这究竟意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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