Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

repeating elements in common lisp [closed]

I am try to create a function with two arguments x and y which creates a list of y times repeated elements X but im getting confused on how to do it which or which method to use i think list compression can do but i want a shorter and simple method for example i want my simple code to be like this

if y = 4
 and x = 7
 result is list of elements (7, 7, 7, 7)

how can i go about it any ideas?? books links or anything that will give me a clue i tried searching but i have not been lucky

like image 385
user1806672 Avatar asked Nov 29 '22 02:11

user1806672


1 Answers

You can use make-list with the initial-element key:

CL-USER> (make-list 10 :initial-element 8)
   (8 8 8 8 8 8 8 8 8 8)

While a good example of how you can code such a function by yourself is provided by Óscar answer.

like image 70
Haile Avatar answered Dec 05 '22 01:12

Haile