2016-11-08 41 views
0

我想弄清楚如何我能够将列表中的值传递给函数。球拍通过列表元素到函数

例:

(define l (list (list 1) (list 2) (list 3 4))) --> l = '((1) (2) (3 4)) 

(define (myFunc el1 el2 el3) 
    ...Whatever is in my function). 

因此,我将如何能为L打电话myFunc的与元素, 我会(myFunc '(1) '(2) '(3 4))

+0

'(apply myFunc l)'? – Sylwester

回答

0

尝试使用apply。例如:

(define l (list (list 1) (list 2) (list 3 4))) 

(define (my-func el1 el2 el3) 
    (+ (length el1) (length el2) (length el3))) 

(apply my-func l) ; => 4 

Here是文档。

+0

非常感谢!还有一个问题。如果我想将我的列表值传递给宏,该怎么做?例如:(define-syntax myMacro(syntax-rules()(myMacro ...))) – RichardHendrix