Вопрос

how does one create a list from a list,what function can i really use i was thinking of using mapcar or maplist with cons together but im not getting any fruitful results,lets say i have a list (a b) then i want a function that will create a list containing the same elements but they should be inform of lists like this ((a) (b)) ,any ideas on how i can solve this problem?? is there a function a use to it?

if i have a list(a b)
the result should be ((a)(b))

thanks guys

Это было полезно?

Решение

What you want to do is this:

(defun listify(ls) 
    (mapcar (lambda (elem) (list elem))  ls))

EDIT

Which is the same as (Thanks to @RainerJoswig):

(defun listify(ls) 
    (mapcar #'list ls))

And if you do:

(listify (list 1 2 3))

or

(listify '(1 2 3))

The output will be:

((1) (2) (3))
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top