Expressing an Append comman in Cons

Discussion of Common Lisp
Post Reply
westbaker
Posts: 6
Joined: Wed Dec 29, 2010 10:01 am

Expressing an Append comman in Cons

Post by westbaker » Mon Jan 03, 2011 9:24 am

Hey everyone,
Im completely new in the lisp world, and i was just doing some programming and would be very grateful to anyone who could help.

In a program i am writing i have one particular line which uses append and takes values such as:

(append '((1 (X 1) (X 1)) (1 (X 1) (Y 1))) '((1 (X 1) (X 1)) (1 (X 1) (Y 1))))
this gives:
((1 (X 1) (X 1)) (1 (X 1) (Y 1)) (1 (X 1) (X 1)) (1 (X 1) (Y 1)))

This is correct for my program, however what i want to do is change the append for a CONS to give the same final answer, however i am finding this increasingly difficult. Just wondering if there was a very simple way to do this.

Thank you in advance

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: Expressing an Append comman in Cons

Post by nuntius » Tue Jan 04, 2011 10:42 am

Append takes lists and returns a list with their contents concatenated.

nil is a list of length 0. (cons x nil) is a list of length 1. (cons x y) is a normal list if y is a normal list; it is a "dotted" list otherwise. Append does not accept dotted lists.

Maybe that helps? Otherwise, you will have to be more specific. For example, show a function call (including arguments) and the desired output. Showing your broken code is also recommended.

westbaker
Posts: 6
Joined: Wed Dec 29, 2010 10:01 am

Re: Expressing an Append comman in Cons

Post by westbaker » Wed Jan 05, 2011 9:22 am

Cheers, thanks very much, that has helped.

Post Reply