可以将Scheme扩展为参数吗?

Dea*_*ing 6 lisp scheme

考虑到我有一个程序(plus x y)巫婆只需要两个args.现在我还有一个包含两个对象的列表(list 1 2).所以,如果有任何神奇的方法将列表扩展为两个参数.我们有一个点概念版本,但这不是我想要的.我只想扩展列表使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
Run Code Online (Sandbox Code Playgroud)

Bar*_*mar 12

(apply your-procedure your-list)
Run Code Online (Sandbox Code Playgroud)


Ósc*_*pez 5

这是Scheme的等效代码:

(define (plus x y)
  (+ x y))

(plus 1 2)
=> 3

(define a (list 1 2))
(apply plus a)
 => 3
Run Code Online (Sandbox Code Playgroud)

扩展列表并将其作为过程的参数传递的“魔术”方法是使用apply。详细了解您的口译员文档