gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
lisp cons two lists
- User
lisp cons two lists
- Assistant
In Lisp, the
consfunction can be used to create a new list by adding an element to the beginning of an existing list. To concatenate, or join, two lists together, you can use theappendfunction. Here are examples of both methods:Using
cons:(setq list1 '(1 2 3)) (setq list2 '(4 5 6)) (cons list1 list2) ; creates a new list containing both original listsOutput:
( (1 2 3) 4 5 6 )Using
append:(setq list1 '(1 2 3)) (setq list2 '(4 5 6)) (append list1 list2) ; concatenates list2 onto list1Output:
(1 2 3 4 5 6)