函数式编程中,Mathematica与Ruby在注入概念上有何相似之处?
- 内容介绍
- 文章标签
- 相关推荐
本文共计325个文字,预计阅读时间需要2分钟。
是的,Ruby 中有类似 Mathematica 注入函数的功能。例如,如果你想计算列表中元素的乘积,在 Ruby 中你可以这样写:
rubylist.inject(1) { |prod, el| prod * el }
而在 Mathematica 中,你可以使用 `Product` 函数:
mathematicaProduct[lst]
这两个函数都用于计算列表中所有元素的乘积。
本文共计325个文字,预计阅读时间需要2分钟。
是的,Ruby 中有类似 Mathematica 注入函数的功能。例如,如果你想计算列表中元素的乘积,在 Ruby 中你可以这样写:
rubylist.inject(1) { |prod, el| prod * el }
而在 Mathematica 中,你可以使用 `Product` 函数:
mathematicaProduct[lst]
这两个函数都用于计算列表中所有元素的乘积。

