With the DUP function if I write
(dup '(2 3) 3) this is ((2 3)(2 3)(2 3))
but what if I want (2 3 2 3 2 3) ?
I could write (flat (dup '(2 3) 3)) but that is a little cumbersome. Could the DUP function be modified so that I could write (dup 2 3 3) where it is understood that multiple previous arguments are duplicated in order?
Will this work?
(define (DUP)
(flat (dup (chop (args)) ((args) -1))))
> (DUP 1 2 3)
(1 2 1 2 1 2)
> (DUP 1 10)
(1 1 1 1 1 1 1 1 1 1)
> (DUP '(1 2) 10)
(1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2)
> (DUP '(1 2) "A" 5)
(1 2 "A" 1 2 "A" 1 2 "A" 1 2 "A" 1 2 "A")
> (DUP 5)
()
Or this?
(define (DUP)
(apply append (dup (chop (args)) ((args) -1))))
> (DUP 1 2 3)
(1 2 1 2 1 2)
> (DUP 1 10)
(1 1 1 1 1 1 1 1 1 1)
> (DUP '(1 2) 10)
((1 2) (1 2) (1 2) (1 2) (1 2) (1 2) (1 2) (1 2) (1 2) (1 2))
> (DUP '(1 2) "A" 5)
((1 2) "A" (1 2) "A" (1 2) "A" (1 2) "A" (1 2) "A")
> (DUP 5)
()