August 19, 2024

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)

lisp

(defun dupli (lista int &optional (ini int))
    (cond ((eql lista nil) nil)
          ((<= int 0) (dupli (cdr lista) ini ini))
          (t (cons (car lista) (dupli lista (1- int) ini )))
    )
)
Be first to comment
Leave a reply