我有一个函数,它接受一个可变长度的参数列表。并且取决于它的长度,我必须调用另一个函数,但参数长度不同。您会看到以下功能:
(define (set-contents . args)
(define columns-length (length args))
(cond
((= columns-length 1)
(send output-list set (empty-list rows-length) (get-nth-item columns-as-list 0)))
((= columns-length 2)
(send output-list set (empty-list rows-length) (get-nth-item columns-as-list 0) (get-nth-item columns-as-list 1)))
((= columns-length 3)
(send output-list set (empty-list rows-length) (get-nth-item columns-as-list 0) (get-nth-item columns-as-list 1) (get-nth-item columns-as-list 2)))
((= columns-length 4)
(send output-list set (empty-list rows-length) (get-nth-item columns-as-list 0) (get-nth-item columns-as-list 1) (get-nth-item columns-as-list 2) (get-nth-item columns-as-list 3)))
这个 cond 子句还可以更长。它正在工作,但绝对不合适。
有没有更好的方法来填补这个功能?