LISP---Consolidated list

Summary of operations on merging lists in LISP:
Let’s look at a few examples first:

CL-USER 51 : 1 > (setq l1 '(1 2 3))
(1 2 3)

CL-USER 52 : 1 > (setq l2 '(4 5 6))
(4 5 6)

CL-USER 54 : 1 > (append l1 l2)
(1 2 3 4 5 6)

CL-USER 53 : 1 > (cons l1 l2)
((1 2 3) 4 5 6)

CL-USER 58 : 1 > (append (list l1) (list l2))
((1 2 3) (4 5 6))

CL-USER 58 : 1 > (append (list l1) (list l2))
((1 2 3) (4 5 6))

CL-USER 59 : 1 > (cons l1 (list l2))
((1 2 3) (4 5 6))

CL-USER 59 : 1 > (cons l1 (list l2))
((1 2 3) (4 5 6))

From the above example, we can get the following analysis:

  1. append can accept n (n >= 2) parameters. If these parameters are all lists, the elements in each list after the first list will be placed after the first list;
  2. cons can accept 2 parameters. If these parameters are all lists, the elements in the first list and the second list will form a new list;
  3. If the two lists to form a new list for the element, you can use (append (list l1 ) (list l2) )or (cons l1 (list l2) ).

Guess you like

Origin blog.csdn.net/Miha_Singh/article/details/89197676