0

我正在尝试在方案中使用“映射”和“累积”函数将未知数量的列表排序到一个列表中,第一个列表将包含旧列表的所有第一个位置,依此类推。

(1 2 3.. ) (4 5 6..) (7 8 9..)...

到这个列表:

(1 4 7) (2 5 8) (3 6 9).

我在写这个:

(accumulate (lambda (x y) (if  (null? y) x (map cons x y))) null '((1 2 3) (4 5 6) (7 8 9) (9 10 11) (12 13 14)))

最后它一直给我带来恼人的点......

((1 4 7 9 . 12) (2 5 8 10 . 13) (3 6 9 11 . 14)).

似乎是什么问题?谢谢!

4

2 回答 2

0

试试这个:

(if (null? y)
    (map list x)
    (map cons x y))
于 2010-12-10T17:36:06.367 回答
0
(define (accumulate x . rest)
  (append (list x) rest))

> (map accumulate '(1 2 3) '(4 5 6) '(7 8 9))
=> ((1 4 7) (2 5 8) (3 6 9))
> (map accumulate '(1 2 3 4) '(5 6 7 8) '(9 10 11 12) '(13 14 15 16))
=> ((1 5 9 13) (2 6 10 14) (3 7 11 15) (4 8 12 16))
于 2010-12-11T08:07:50.687 回答