Looking to complete my self-obsessive list of cdr, car functions

Looking to complete my self-obsessive list of cdr, car functions

Anonymous
Not applicable
1,356 Views
6 Replies
Message 1 of 7

Looking to complete my self-obsessive list of cdr, car functions

Anonymous
Not applicable

I am trying with all my might to gain understanding of car, cdr, etc. for some specific projects.

 

I've made a list of functions and have been typing them in the ACAD command line to see what works and what doesn't.  Yes, OK, I'm a monkey trying to type Shakespeare....Smiley LOLSmiley LOLSmiley LOL

 

My list is (1 2 3)(4 5 6)(7 8 9).

 

I can't find a way to extract 6, 8 or 9.  Also, can't get (8 9)

 

I've attached a text file that shows my accumulated list.  Could someone fill in these blanks for me?  Thanks very much in advance!! Smiley Happy

0 Likes
Accepted solutions (1)
1,357 Views
6 Replies
Replies (6)
Message 2 of 7

Ranjit_Singh
Advisor
Advisor
Accepted solution
Command: (cddadr '((1 2 3) (4 5 6) (7 8 9)))
(6)
Command: (cdaddr '((1 2 3) (4 5 6) (7 8 9)))
(8 9)

car cdr can only be nested upto 4 levels

 

, so to extract 6 and 8 and 9 as car's and not lists ...

 

Command: (car (cddadr '((1 2 3) (4 5 6) (7 8 9))))
6
Command: (car (cdaddr '((1 2 3) (4 5 6) (7 8 9))))
8
Command: (cadr (cdaddr '((1 2 3) (4 5 6) (7 8 9))))
9
Message 3 of 7

Anonymous
Not applicable

Great!  Thanks!  I learned a lot from your answer Smiley Very Happy

0 Likes
Message 4 of 7

martti.halminen
Collaborator
Collaborator

 

A style hint: while understanding the CxxxR functions is useful, they should be hidden inside higher-level tools or your programs will be pretty hard to read.

 

For example picking out 6 from that list would be more readable as 

 

(z (second '((1 2 3)(4 5 6)(7 8 9))), assuming your application is using x,y,z coordinates.

 

- Defining Z and SECOND should be easy for you at this stage.

 

-- 

Message 5 of 7

Anonymous
Not applicable

Hahaha, it can be done THAT easily? Smiley LOL Thanks for the extra tip, the example code I'm learning from is definitely NOT that straightforward Smiley Happy

0 Likes
Message 6 of 7

pbejse
Mentor
Mentor

I downloaded a .txt file sometime ago specifically for car / cadr   combinations [ cant remember where though ] 

 

These concatenations are the equivalent of nested calls to car and cdr. Each a represents a call to car, and each d represents a call to cdr

 

Read through it, either you will have a better understanding on how the nesting works or give you a massive headache 🙂

 

pBe

Message 7 of 7

Anonymous
Not applicable

Thanks for the list!

0 Likes