LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-06-2011, 04:10 PM   #1
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
confused about cons (Lisp)


Breaking down the cddar function, I arrived at the following:

Code:
CL-USER> (cddar '((a b c) (d e f) g))
(C)
CL-USER> (cddr '(a b c))
(C)
CL-USER> (cdr '(b c))
(C)
(c) is, if I understand correctly, a list, or a chain of cons consisting of c and nil:
Code:
(cons 'c nil)

If I look at this example:

Code:
CL-USER> (cadadr '((a b c) (d e f) g))
E
CL-USER> (cadar '((d e f) g))
E
CL-USER> (cadr '(d e f))
E
CL-USER> (car '(e f))
E
Why doesn't it include parentheses? What is different here? What is E? I mean is it still a list?

Last edited by sycamorex; 10-06-2011 at 04:12 PM.
 
Old 10-06-2011, 05:22 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
It's easier to see why when you break the lists down into the binary trees they actually are. The list (b c) would correspond to
Code:
  /\  
 b /\
  c  nil
"car" returns the left branch, and "cdr" returns the right branch. The left branch is just the atom b, and the right branch is a cons with the atoms c and nil, which is otherwise known as a list with one element.
 
1 members found this post helpful.
Old 10-06-2011, 05:25 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836

Original Poster
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Aarrgh! Why haven't I thought of this?! Thanks a lot. It makes sense.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lisp IDE d00bid00b Debian 1 11-13-2010 01:07 PM
Lisp and Java and C++ and WHAT???? vargadanis Programming 21 12-12-2006 06:17 AM
LISP or COMON LISP Compiler for Debian carspidey Programming 3 04-19-2006 07:46 AM
Lisp phoenix7 Programming 4 09-24-2004 07:40 AM
Lisp, emacs-lisp aizkorri Programming 1 09-04-2002 06:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration