Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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?

Best Answer

  • 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 ...

Sign In or Register to comment.
Origami
Origami is the Japanese word for paper folding. ORI means to fold and KAMI means paper and involves the creation of paper forms usually entirely by folding.

Powered by VanillaForums, Designed by Steam