Scheme可以将列表扩展为参数吗? [英] Can Scheme expand a list as arguments?

查看:116
本文介绍了Scheme可以将列表扩展为参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到我有一个过程(plus x y)女巫正好需要两个参数.现在,我还有一个列表,其中包含两个对象,例如(list 1 2).因此,如果有任何魔术方法将列表扩展为两个参数.我们有一个点概念版本,但是不是我想要的版本.我只想扩展列表,以使Scheme相信我传递了两个参数而不是列表.

Considered that I have a procedure (plus x y) witch takes exactly two args. And now I also have a list which contains two objects like (list 1 2). So, if there's any magic way to expand the list as two arguments. We have a dot notion version, but that isn't what i want. I just want to expand the list to make Scheme believe I passed two arguments instead of a list.

希望这些Ruby代码有帮助:

Hope those Ruby codes help:

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 your-procedure your-list)

这篇关于Scheme可以将列表扩展为参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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