Variables Types


Please post comments to discussion thread

in AutoLISP (we will talk about VL later)

A variable is a container to store a value. The kind of value is a variable type. The descriptions of the variables are listed below.

Code:
Boolean
Dotted Pair
Entity
Integer
List
Real (single)
Selection Set
String
In AutoLISP you have the above list of variable types

You can create and set the value of a variable using the following couple options

Code:
(setq intVariable 1.0)
(set 'intVariable 1.0)
If you are not familiar with the set expression is because most programmers use the setq instead.

The nice thing about set is you can have the program create its own variable names. (VB.net, C# and C++ cannot.)

Variable naming

I prefer to use a naming style that is similar to the Reddick Naming Convention used in VB.

The variable names using this style include a 2 or 3 letter prefix like ss (for selection set) or int (for integer) that describes the variable type.

The rest of the name is a clear descriptions of the contents like ssSelections, intCount, strFullName, lstObjects etc...

I use the same name consistently to help me be able to immediately understand the variable.

I avoid using abbreviations in my names and only use single letter variables in lambda expressions.

Variable Types:

Boolean is a true/false variable but in LISP it is T/nil

T is a true atom and nil is nothing.

Example boolean variable name: blnFlag

Dotted Pair is a special kind of two item list.

It is used in entity lists frequently (which we talk about later) but I try to avoid it.

The first item is available using the (car dprPair) and the second item is available using (cdr dprPair)

This is not true for lists where the second item is available by (cadr lstPair)

I will talk more about lisp manipulation later.

Example dotted pair variable name: dprPair

Entity is a pointer that allows the programmer to access and modify entities in memory.

Example entity name variable name: entSelection

Integer is a whole number +32767 to -32678 for some expressions (like ssname) and +2,147,483,647 to -2,147,483,648 for others.

I just assume the lower range.

Example integer variable name: intCount

List

A list is a powerful variable type that can contains a list of other variables including other lists!

for example (list "A" "B" "C" 1 2 3 1.0 2.0 3.0 (list "a" "b")) is valid.

The Visual Studio programming languages have difficulty mixing variable types but LISP doesn't.

Example list variable name: lstSelections

Real numbers are 16 decimal places (max) positive and negative single precision real numbers.

Example real number variable name: sngValue

Selection Set is a lisp variable type that is created by the ssget expression.

Example selection set variable name: ssSelections

It is a series (not a list) of entityname that can be indexed and read using the ssname expression.

String is a variable that contains a series of alpha numeric characters.

WHen you create them you need to place double quotes at the start and finish of the series

Example: "This is an example of a string"

Example string variable name: strFullName

There are more variables in Visual LISP but this is a good place to start.

If you don't understand any of them I would suggest researching them more.

Also the variable naming is a personal preference option.

There is good reason to use very descriptive naming that you will see later.

Good consistent habits pay great dividends later!!!