I understand that by using cons we could have something like :
> (cons 'b 'c)
(B . C)
And that happens because the cell is split into two and the values are B and C.
My question is, can you get the same result using list?
You can't get list to return a dotted list, because "the last argument to list becomes the car of the last cons constructed" in the returned list.
But, you can get list* to return a dotted list. With the list* function, the final argument becomes the cdr of the last cons, so:
CL-USER> (list* 'a '(b))
(A B)
CL-USER> (list* 'a 'b '())
(A B)
CL-USER> (list* 'a 'b)
(A . B)
CL-USER> (list* 'a '(b c))
(A B C)
CL-USER> (list* 'a 'b '(c))
(A B C)
CL-USER> (list* 'a 'b 'c '())
(A B C)
CL-USER> (list* 'a 'b 'c)
(A B . C)
For example, (list* 'a 'b 'c '()) and (list 'a 'b 'c) are both equivalent to:
CL-USER> (cons 'a (cons 'b (cons 'c '())))
(A B C)
But (list* 'a 'b 'c) is equivalent to:
CL-USER> (cons 'a (cons 'b 'c))
(A B . C)
And, (list* 'a 'b) is equivalent to:
CL-USER> (cons 'a 'b)
(A . B)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With