球拍将列表元素传递给函数

时间:2016-11-08 05:51:21

标签: scheme racket

我试图弄清楚如何将列表中的值传递给函数。

前:

(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))

1 个答案:

答案 0 :(得分: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是文档。

相关问题