Let's step thru the challenge whdjr posted. (He wanted to take a list and separate it into separate lists of two.) It sounds harder then it really is. Its actually a real simple task.
So lets take a list of ten numbers. (It can be any number, but lets just stick to round numbers for now.) Now imagine that this list is a collection of real world objects. (Let's use coins. --pennys) Now if you had ten pennies and you wanted to separate that pile into piles of two how would you do it? Well, you would just pull off two pennies off the pile and line them up until you didnt have a pile right?! (Simple) Well the same thing goes for a list in AutoLisp. You just start pulling off two items of the list at a time till you dont have a list anymore.
Now that you have the basic concept of what you want to accomplish down lets put into code. (PseudoCode to be exact.) Pseudo code is nothing more then what we just did in our head, its just putting our procedure down in English in separate statments.
Pseudo code:
Objective: Take a list and split it into smaller separate lists of two.
Arguments: A list to split into pieces.
Date: 01.27.05
Code:
o Iterate thru a list until there are no more members
o Pop off two items and create a list out of them
o Construct / append a new list of these smaller lists
o Return the new list of smaller lists.
Now that we have our ideas worked out in English we examine that code for any potential problems we can see.
Can you think of any problems with our code sofar? hummm... Well right away I see that if our list is an odd number we are going to have a "remainder" list left over. Now we ask ourselves what application is this for and how are we intending to use it? If we know that we are always going to have an even amount of data I wouldnt worry about appending our design. Now if we are to get an unknown amount of items I would want to append our code to either toss out the remainder or just not run at all, but for this example it is to be assumed that we will always have an even amount of data.
I want you to find at least one AutoLisp functions for each statement in our PseudoCode. (e.g. "iterate thru a list..." We can use either a "while", "mapcar" or a "foreach" function.)