I want mylist
to have the same functionality as list
. In most Lisps (I'm on Emacs Lisp) I can simply write
(defalias 'mylist 'list)
But if I want to write my own I can write
(defun mylist (&rest x)
(car (list x)))
which has the same functionality. But then I got this by experimenting. First, I had this code
(defun mylist (&rest x)
(list x))
which produced a list in a list. I wasn't sure why, but the simple solution was to just put (list x)
inside a car
and call it good. But I'd like to know why I get a list inside a list when I don't use the car
trick. What am I missing?
(defun my-list (&rest x) …
The &rest
parameter means that all remaining arguments are put into a list that is bound to this parameter. X
then holds the list that you want. You're done.
(defun my-list (&rest x)
x)