- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
lambda
被称为 lambda 而 proc
被称为 proc 是否有原因?
公平地说,我记得两者都是匿名函数……这就是与 Lambdas 的相似之处。他们不像 Haskell 的 lambda 那样接受 1 个参数。
为什么一个叫 lambda 而两者可以等同地称为 lambda?
为什么有人用“proc”命名第一个,用“lambda”命名第二个?
附言。它们都在一个类中,Proc
。有方法 lambda?
显示它是否是 lambda。
最佳答案
在 ruby 中,lambda 是一种特殊的 Proc 对象,其行为模仿方法的行为。特别是,它会尊重 arity:如果你给它错误数量的 args,它会吐出一个错误。
请参阅此答案(对一个不相关的问题)以了解它们之间的不同之处:
Why does Hash#select and Hash#reject pass a key to a unary block?
回复评论:lamba和proc都产生一个Proc对象。唯一的区别是上述关于 arity 的行为,以及 return 语句会发生什么(请参阅问题评论中的相关链接)。
至于为什么要这样命名,只要看看 Matz 的选择就知道了:这是最自然的选择。他在一次采访中定义了他的意思:
Everyone has an individual background. Someone may come from Python, someone else may come from Perl, and they may be surprised by different aspects of the language. Then they come up to me and say, 'I was surprised by this feature of the language, so Ruby violates the principle of least surprise.' Wait. Wait. The principle of least surprise is not for you only. The principle of least surprise means principle of least my surprise. And it means the principle of least surprise after you learn Ruby very well. For example, I was a C++ programmer before I started designing Ruby. I programmed in C++ exclusively for two or three years. And after two years of C++ programming, it still surprises me.
http://en.wikipedia.org/wiki/Ruby_(programming_language)#Philosophy
在这种情况下,请注意 lambda 的行为如何非常像一种方法,并且在这方面有资格作为(匿名)函数。而 proc 则没有。命名这些“lambda”中的第一个似乎是一个自然的选择(无论如何对我来说),而第二个则不会,因为在 arity 和 return 语句方面存在差异。
关于ruby - Lambda 和 proc 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21215780/
在经历了DDOS攻击后,不知何故/proc/kcore非常巨大,我使用一个小的php类来检查当前的磁盘空间,以及已经使用了多少。 它显示以下内容: Total Disk Space: 39.2 GB
所以我从 ruby 移植了一个工具,可以在对象上定义回调 block ,我希望在设置回调的情况下调用它。所以基本上是这样的。 def set_block(&block) @new_kid_on
我定义了两个脚本:第一个脚本调用第二个脚本中的 proc。第二个脚本定义了一个命名空间 fooSpace , 定义了一个变量 fooValue内fooSpace , 并定义了一个过程 myProc内f
使用一个 proc 时,我的脚本工作正常(检索 sftp 提示)。但是当我尝试在 proc 中使用 proc 时,脚本卡住了,我不知道为什么。 请不要重构代码,这不是重点,我需要了解这里的问题。 工作
我想知道是否有一种方法可以识别某些proc文件中用于DMA映射的内存,例如mtrr和iomem,或者通过lspic -vv . 在我的/proc/mtrr中,只有一个无法缓存区域,它似乎几乎指向3.5
我有 2 个过程,它们一个接一个地调用。第一个过程使用 diff 功能并创建 file.txt。压缩文件后的过程。问题是当我运行脚本时,file.txt 是空的。当我注释掉压缩过程时,文件中打印了差异
我曾经认为 /proc/self 和 /proc/$$ 在 bash 终端中是一样的,但现在我发现它们是不同的。 我知道$$是当前进程的pid,/proc/self是当前运行的进程,应该是bash终端
在下面的程序中,我想在第 2 个过程中捕获数据包,而 ping 在第 1 个过程中运行。现在,如果我执行这个程序,proc 正在运行 ping 并退出它。有解决此问题的想法吗? 我的 TCL 代码:
在 proc 中,您可以获得 proc 名称(无需对其进行硬编码)吗?例如 proc my_proc { some_arg } { puts "entering proc [some way
我有一个自定义的 A10 存储库,我试图在其中创建一个能够读取 /proc/[pid]/some-file 的应用程序文件,例如stat和 status ,有点像 ps做。 看完这篇 answer很明
我是 TCL 的新人。我通过 Windows Vista 下的 DOS 窗口“tclsh85 FOD/Scripts/program1.tcl”执行 TCL 代码。 program1.tcl 包含“s
我想查看每个进程的精确内存量用作匿名页,因为匿名内存不能调出,因此精确跟踪此使用情况非常重要。 获取匿名页面总数的一种方法是读取/proc/meminfo AnonPages。 另一种方法是将 sma
在 Ruby 中,Proc.new { 'waffles' } 和 proc { 'waffles' } 之间有什么区别吗?我发现很少有人提到第二种语法。 使用 irb 进行测试,我没有发现任何明显的
我正在寻找有关Linux系统上/proc/net/nf_conntrack和/或/proc/net/ip_contrack文件内容的详细文档。 是的,我知道,有许多实用程序可以用人类可读的格式向我显示
而不是执行多个单独的 PROC FREQ一个非常大的数据集上的程序,我想通过执行单个 PROC FREQ 来提高效率与多个 TABLE声明。我们的 QA 流程需要表格标题,这很简单,只需一个 TABL
我想在 /proc/driver 下创建一个文件目录。我想使用像 proc_root_driver 这样的宏(或提供的其他东西)而不是明确使用“驱动程序/模块名称”。我用 create_proc_en
在 SQL Server 2005 中,我希望名为 LimitedUser 的用户只能运行一个过程: GRANT EXEC ON [usp_RunETL] TO [LimitedUser] 但是,该
考虑到以下两个过程: proc firstOne(): void = echo "X" proc secondOne(): void = echo "X" discard 它们
我想使用 PROC TABULATE 复制 PROC MEANS 的输出。原因是我希望将利润百分比(或利润率)作为 PROC MEANS 输出中的变量之一,但希望抑制一个或多个统计数据的计算,即会有一
我的目标是使数据适合具有正支持的任何分布。 (威 bool (2p)、 Gamma (2p)、帕累托 (2p)、对数正态 (2p)、指数 (1P))。第一次尝试,我使用了 proc univariat
我是一名优秀的程序员,十分优秀!