APPENDing dotted pairs

I'm creating a Lisp-Tutorial for a bunch of Co-workers at my company and stumbled over a (for me) strange
behaviour of APPEND when used on dotted pairs.
For the sake of demonstration I tried to show some porperties of dotted pairs:
(listp (cons 1 2)) => T
(atom (cons 1 2)) => nil
and so on.
But I expected append throwing an error when I try something like this:
(append (cons 1 2) (cons 3 4))
instead I get
(1 3 . 4)
I have no AutoCAD at hand to check if it behaves the same.
Can somebody enlighten me on this strange kind of list?
And where's the 2?

Comments

  • Dear Austrobass,

    same in AutoCAD :-) it even errors on "(append (cons 1 2) (cons 3 4))" ...

    "append" function, in our online developer docs :

    (append [ list [ list ... ]] )
    This function appends all provided list arguments as one list; each list argument must be a list.

    you will need
    (append (list (cons 1 2)) (list (cons 3 4)))
    for plain dotted-pairs - dotted-pairs are partially acting like a list, but they are not real "lists" ...

    "append" assumes the first argument would be a list, but dotted-pair is not ... so "2" is replaced by the subsequent list (or dotted-pair)

    hope this explains a bit ...