List evaluation in LISP (strange behaviour of cons)
cons, lisp, list, racket, scheme
Solution
`cons` returns a dotted pair, not necessarily a list.
`(cons 1 2)` returns `(1 . 2)`
`(cons 1 null)` returns `(1)`
`(cons 1 (cons 2 null))` returns `(1 2)`
Problem
I am currently playing around with LISP. Everything is fine, but I can't understand the following issue. I have the this append-operation: ``` (define (append l1 l2) (if (eq? l1 null) l2 (cons (first l1) (myappend (rest l1) l2)))) ``` I use it like this: ``` (myappend (cons (cons 1 2) null) '(4 5)) ``` And the result in Racket is: ``` '((1 . 2) 4 5) ``` But why? In my oppinion it should be '(1 2 4 5), because cons returns a list and myappends appends two lists. Can anybody help me? What is LISP doing?