AutoLISP Distinguishes among Several Data Types

The bulk of this class will concentrate on learning the functions of AutoLISP. But, each of these functions requires certain types of arguments for the AutoLISP expression to make sense. For example, a function that adds two numbers together would require that its arguments be numbers.

We need to be able to distinguish among five different data types: integers, reals, strings, lists, and symbols. We will learn about additional data types when we discuss AutoCAD entities and selection sets in later sections.

  • Atoms are anything that is not a list.

Integers (Whole Numbers)

An integer is any number without an explicit decimal point. Integers are most frequently used when counting (“Enter number of rows: ”) or when making a selection (“1” is on, “0” is off).

  • May be preceded by optional “+” or “-”.
  • AutoLISP uses 32 bit values internally, but some commands can accept only 16 bit values (-32,768 to +32,767). Greater values will be converted to reals to be passed to AutoCAD.
  • An integer evaluates to itself.


Examples of Integers
12, -18, 0, 32767

A real is any number with an explicit decimal point. Reals are commonly used to designate such things as coordinates of a point, distances between two points, angles (although AutoLISP uses radians to measure angles), or for any other value that can vary by fractional components.

  • Real numbers between -1.0 and 1.0 must have the zero placed before the decimal point. Example: -0.125 or 0.0625.
  • AutoLISP commands that expect reals can accept integers. Example:(getreal “Type in a Real Number: ”) 12
  • Reals may be expressed in exponential (or scientific) notation.
  • A real evaluates to itself.
See also  why AutoLISP in AutoCAD?

Command: !2.79

Examples of Reals
2.32, -1.0789, 0.0, 1.2E+07


Answer the following questions. Estimated time for completion: 5 minutes.

1. Which of the following are not valid integers? Why or why not?


2. Which of the following are not valid reals? Why or why not?


3. Compare the results of the following two expressions:

(/ 12.0 5.0)
(/ 12 5)

Notice the different results in # 3 above. Since the two arguments in the first expression are both reals, AutoLISP returns a real value as a result. However, in the second expression, AutoLISP uses integer arithmetic and truncates (does not round) the result to an integer value. Be careful when doing division of integer values.

A string is any alphanumeric character enclosed in double quotes. Strings are commonly used to designate AutoCAD commands and options, filenames, directory paths, and AutoCAD system variables. Anything in AutoCAD you would normally type in at the keyboard must be enclosed in quotes.

A string evaluates to itself.

Command: !”APPLE”

Typing Directory Names in AutoLISP
Note the use of forward slashes to separate directory levels above. Backslashes have special meaning in AutoLISP that we will learn about later. Forward slashes or double backslashes are used to separate directory levels within AutoLISP.
“c:/blocks/mech/bearing.dwg” or


A list is any expression enclosed in parentheses. Lists are used to designate fundamental AutoCAD properties: 2D and 3D points and entity definitions.

  • Elements of a list can be integers, reals, strings, symbols, or even other lists. We’ll soon see that every AutoLISP expression is enclosed in parentheses and is, therefore, a list.

Symbols are AutoLISP’s variable names.

  • They may be any printable character except: a space, open parentheses, closed parentheses, period, single quote, double quote, semi-colon, i.e. ( ) . ’ “ ;
  • Numbers alone may not be used as symbols, but can be combined with other valid characters to form a valid symbol.
See also  AutoCAD and AutoLISP are Two Separate Programs

Not valid: 12, -46
Valid: A1, 3C

  • Symbol names are not case sensitive. The symbols PT and pt are equal. For consistency in this book we will capitalize symbol names while leaving all other functions and arguments in lower case.
  • In the past, symbol names were usually kept short to reduce typing. However, the Visual LISP text editor now has tools to speed up the input of names. Therefore, it is a good idea to make your symbol names long enough to make clear what information the symbol is storing. For example, instead of RN and CN, use ROW_NUMBER and COLUMN_NUMBER.

Examples of Symbols

Special Symbol Names
There are several special symbols that are defined by default. Some examples are PI (3.14159), T (stands for True or non-nil), NIL (empty) and any AutoLISP function name. Do NOT redefine these symbols.

Beware of using a function name as a symbol name. For example, ANGLE1 is fine, but ANGLE is an AutoLISP function.
Visual LISP will warn you if you start to redefine one of the AutoLISP functions.


Answer the following questions. Estimated time for completion: 5 minutes.

1. Indicate the data type that is used to express the following AutoCAD expressions in AutoLISP:

See also  Storing and Setting AutoCAD’s System Variables with Autolisp

2. Which of the following strings are invalid?

“This is a string.
” ”

3. Which of the following lists are invalid?
(A B C) D E)
(1.0 2.0 (3.0))
(“This is a string”    6.0   5    A)

4. Which of the following symbols are invalid?


Self Check:

Four Principles of AutoLISP

1. Where are mathematical operators positioned in an AutoLISP expression?

2. How does AutoLISP distinguish between real and integer numbers?

3. What is a list?

4. Name five data types that are used within AutoLISP.

Back to top button