【发布时间】:2013-06-11 02:39:36
【问题描述】:
考虑到我有一个程序(plus x y)witch 正好需要两个参数。现在我还有一个列表,其中包含两个对象,例如(list 1 2)。因此,如果有 any 神奇的方法可以将列表扩展为两个参数。我们有一个 dot notion 版本,但这 不是 我想要的。我只想扩展列表,让 Scheme 相信我传递了两个参数而不是列表。
希望这些 Ruby 代码有所帮助:
a = [1, 2]
def plus(x,y); x+y; end
plus(*a)
# See that a is an array and the plus method requires
# exactly two arguments, so we use a star operator to
# expand the a as arguments
【问题讨论】:
-
请记住,您也可以使用 apply 进行 curry。例如。而不是 (apply map (cons list list-of-lists)) 你做 (apply map list list-of-lists)