One of the many attributes that makes Common LISP an excellent candidate for artificial intelligence and the perfect model for AutoLISP is its ability to store large amounts of data in the form of a list. A list is nothing more than a collection of data that is either related or non-related to a particular entity or event. For example, a list describing the characteristics of a line could include the Entity Name, Entity Type, Entity Handle, Entity Color, Layer, Starting Point, and Ending Point. A list can also consist of a set of instructions or commands describing a particular sequence of events. For example, a list containing the steps for determining the area of a circle given only its diameter would be:
- Calculate the radius of the circle by dividing its diameter by two.
- Square the radius and multiplying the result by 3.14, (producing the area of the circle).
In most cases, lists provide an efficient as well as practical way of storing information over the traditional method of using variables (variables are only able to store a single item known as an atom). This is especially true if the information used by a program varies from execution to execution. For example, to write a program that would find the equivalent resistance of a series circuit and calculate the voltage drop for each resistor at first seems like an easy task to accomplish. First, add up the resistance of all the resistors in the circuit to find the equivalent resistance. Next, divide the total voltage supplied to the circuit by the equivalent resistance, producing the current supplied to the circuit. Finally, the voltage drop for each resistor can be found by multiplying the current by the resistance of the individual resistor. However, there is one small problem, the number of resistors could vary from circuit to circuit making it extremely difficult if not impossible to create a generic program using variables. An alternative is to construct a list containing values assigned to each resistor and then setting that list equal to a single variable. Not only does this solve the problem of the variant amount of information entered into the program, but also reduces the number variables used in the program and the amount of code required to create the program. A list can also contain other lists (this is often referred to as a sub-list). Each entry in a list is referred to as an Element. For example, the list (apple orange peach) contains the elements apple, orange and peach. In AutoLISP a list will always start with an opening parenthesis and end with a closing parenthesis.
No comments:
Post a Comment