Loading [MathJax]/extensions/tex2jax.js

2010年7月15日木曜日

Duplicate the elements of a list

;; P14 (*) Duplicate the elements of a list.
;; Example:
;; * (dupli '(a b c c d))
;; (A A B B C C C C D D)
(define (dupli lst)
(let loop ((lst lst) (acc '()))
(if (null? lst)
(reverse acc)
(let ((head (car lst)))
(loop (cdr lst)
(append `(,head ,head) acc))))))
view raw p14.ss hosted with ❤ by GitHub

0 件のコメント:

コメントを投稿