14.3k views
4 votes
What are the differences betweenCONS, LIST, and APPEND?

1 Answer

6 votes

Answer:

These all are constructors.

CONS

(CONS A B)

makes a pair like this: (A . B)

In other words, A is the CAR of the pair; B is the CDR of the pair.

For example:

(CONS 4 5) ==> (4 . 5)

(CONS 4 '(5 6)) ==> (4 5 6)

[The pair (4 . (5 6)) is the same thing as (4 5 6)].

APPEND

(APPEND A B)

makes a new list by replacing the final nil in A with the list B. A and

B must be proper lists.

For example:

(APPEND '(4) '(5 6)) ==> (4 5 6)

This takes any amount of number and put in this order

LIST

In this ,it will return a list whose elements are value of arguments in the order as it appeared in the LIST.It can take any amount of parameters

For example,

(LIST 4) ==> (4)

(LIST 4 5) ==> (4 5)

(LIST 4 5 '(6 7)) ==> (4 5 (6 7))

(LIST (+ 5 6)(* 5 6)) ==> (8 9)

User Yamspog
by
4.9k points