Reputation: 405
Hi guys I am trying to concat a list and to return the first value with extra brackets for example when I call the function (bracket-head '(a b c)) => ( (A) B C ).
I have done it to give the result when I call the function with '('(a) b c)
. So here is my code:
(defun bracket-head (list)
(append (first list) (rest list))
Upvotes: 0
Views: 456
Reputation: 60004
First of all, ()
are parentheses, not brackets.
Next, "extra parentheses" means you wrap the object in a list:
[5]> (list 1)
(1)
[6]> (list *)
((1))
[7]> (list *)
(((1)))
[8]> (list *)
((((1))))
[9]> (list *)
(((((1)))))
Thus, what you need to do is
[13]> (defparameter list (list 1 2 3))
LIST
[14]> (setf (first list) (list (first list)))
(1)
[15]> list
((1) 2 3)
Or, if you do not want to modify the list in-place:
[17]> (defparameter list (list 1 2 3))
LIST
[18]> (cons (list (first list)) (rest list))
((1) 2 3)
[19]> list
(1 2 3)
Upvotes: 2