1 Replies - 6566 Views - Last Post: 05 February 2011 - 06:24 PM

#1 SnoBunny85   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 87
  • Joined: 02-March 10

Combining two lists in Lisp

Posted 01 February 2011 - 09:09 AM

This is my first time ever coding in LISP. I am trying to take two lists and make them appear as below:
(x a x b x c)
When I run this code I get a period between my letters and it only shows the last one as output or I get an error.
Please Help!!


(define distin ())
	(cons 'x (car '(a b c)) cdr '(a b c))(cons 'x (car '(b c) cdr '(b c)))



Is This A Good Question/Topic? 0
  • +

Replies To: Combining two lists in Lisp

#2 Raynes   User is offline

  • D.I.C Lover
  • member icon

Reputation: 614
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Combining two lists in Lisp

Posted 05 February 2011 - 06:24 PM

You're not consing onto the beginning of a list. You're consing two non-collections. Here is an example of the difference:

> (cons 'x 'y)
(x . y)
> (cons 'x '(a b c))
(x a b c)




Besides that, you're not 'calling' cdr, you're passing it as an argument to cons. To be honest, I have not the slightest clue what you're trying to accomplish here, thus I can't really help you. The code makes no sense.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1