Loading [MathJax]/extensions/tex2jax.js

2010年7月15日木曜日

Replicate the elements of a list a given number of times

;; P15 (**) Replicate the elements of a list a given number of times.
;; Example:
;; * (repli '(a b c) 3)
;; (A A A B B B C C C)
(define (repli lst int)
(let loop ((lst lst) (i int) (acc '()))
(cond ((null? lst) (reverse acc))
((< i 1) (loop (cdr lst) int acc))
(else (loop lst (- i 1) (cons (car lst) acc))))))
view raw p15.ss hosted with ❤ by GitHub

0 件のコメント:

コメントを投稿