Lisp the difference between (cons' a (cons' b 'c)) and (cons' a' (bc))

What's the difference between:

(cons 'a (cons 'b 'c)) ;; (A B . C)

and

(cons 'a '(b.c)) ;; (A B.C)

I need to create the following list ((ab) .c) using the cons, so I'm trying to figure out what it is "." is.

LE : I have the following (cons (cons 'a 'b) 'c), but it creates ((A . B) . C), not ((A.B).C)(note the extra spaces)

+3
source share
3 answers

Spaces are used to separate list tokens. A.Bis the only token. (A.B)is a list with one item. (A . B)is a cons cell with Aas a car and Bas a cdr.

"" (). , A, B .. (A . B), . " ". "", "cdr".

cons ​​. , (cons 'a 'b) (A . B). , .

, , , , ((A . B) . C) - , - . , , cdr C. - , A cdr B.

, cons, , cdr . cdr ( NIL Lisp). , , (A . (B . (C . NIL))). , : (A B C). CDR NIL, , . (A . (B . (C . D)))) (A B C . D).

+6

. . b.c - : b,. c.

FOO.BAR, Lisp .

(FOO.BAR), Lisp .

(FOO . BAR), Lisp cons FOO CAR BAR CDR.

. CAR CDR cons: (a . b). ..

(cons 'b 'c) cons b CAR c CDR. (b . c).

(cons 'a '(b.c)) a b.c. (a b.c).

((A.B).C) ((A.B) . C). .

((A.B) . C) cons (a.b) CAR c CDR.

+6

lisp, , , " ", , - , .

In particular, the space after the closing parenthesis is always added, but only for readability. It makes no sense to require that it is not printed.

+1
source

Source: https://habr.com/ru/post/1724938/


All Articles