Jump to content

what items in Autolisp considered as a symbol?


Recommended Posts

Posted

hi

 

what items in Autolisp considered as a symbol?

 

Thanks

Shay

Posted

This ties into your other thread:

hi

 

what items in Autolisp considered as constant?

 

T nil PI Pause

 

they all look like constants but why the developer guide consider them as variables or predefined variables?

It's because of Lisp. Everything which has a name in Lisp is a symbol, and nothing which is a symbol cannot be assigned to - at least not in AutoLisp. So you can "consider" some to be a constant, as nearly everyone does - but AutoLisp itself doesn't do so - to AL the T/nil/pi/pause/etc. are simply symbols the same as any other named symbol. Even defuns and built-in functions can be assigned to. So it's dangerous since you can assign another value to something like PI, but it's also advantageous since you can do something like that without interference from the language itself (if you want to have some parallel universe's value for PI in there you can do so).

 

This aspect of Lisp is tied to a contentious point called Weak Typing, which means any "variable" can be assigned any type of data/code at any time. Strong Typing (like in many other languages) forces the programmer to use only similar types of values in the same variable, e.g. starting a variable as an int type in C and then later trying to assign a string to that will simply error when compiling. This has good and bad to it, in languages like C the compiler does the type checking for you at both compiling and runtime assignment (if you turn this on), in Lisp you need to do the checks if and when you think they're necessary.

Posted (edited)
This ties into your other thread:

It's because of Lisp. Everything which has a name in Lisp is a symbol, and nothing which is a symbol cannot be assigned to - at least not in AutoLisp. So you can "consider" some to be a constant, as nearly everyone does - but AutoLisp itself doesn't do so - to AL the T/nil/pi/pause/etc. are simply symbols the same as any other named symbol. Even defuns and built-in functions can be assigned to. So it's dangerous since you can assign another value to something like PI, but it's also advantageous since you can do something like that without interference from the language itself (if you want to have some parallel universe's value for PI in there you can do so).

 

This aspect of Lisp is tied to a contentious point called Weak Typing, which means any "variable" can be assigned any type of data/code at any time. Strong Typing (like in many other languages) forces the programmer to use only similar types of values in the same variable, e.g. starting a variable as an int type in C and then later trying to assign a string to that will simply error when compiling. This has good and bad to it, in languages like C the compiler does the type checking for you at both compiling and runtime assignment (if you turn this on), in Lisp you need to do the checks if and when you think they're necessary.

 

when i tried:

 

(setq T "true")

 

i got warning that say:

 

assignment to protected symbol

T

Enter break loop?

 

if i press yes, T is still protected, if no, T is redifined

 

what is this break loop?

 

Thanks

Shay

Edited by samifox
Posted
What is this break loop?

 

That behaviour is controlled by the following setting in the Visual LISP IDE, located under Tools > Environment Options > General Options:

 

protected.png

 

Though, it is not recommend to redefine protected symbols, since AutoLISP programs supplied with AutoCAD (such as the Express Tools programs) will be dependent on these protected symbols holding particular values.

 

Lee

Posted

i always find myself thinking about symbols as a "bridge" between human and the machine, so instead of writing nonsense numbers to express what we want to pc to do we use those symbols. im digging on it because the help documentation refer always to terms like , symbol, item, atom , and its easy to get lost.

 

how could you distinguish or define solid explanation of symbol, item, atom as refereed by the autolisp help documentation?

 

Thanks

Shay

Posted

See a symbol as the container of data/code - it's like a name you give something so you can refer to it later.

 

Item is not actually a Lisp thing, it's a way of speaking in English to refer to one thing from a collection of things. We usually use it to refer to one position inside a list.

 

Atom is a Lisp thing which refers to data inside a symbol, where that data is an "atomic" value - i.e. it cannot be split into separate parts. E.g. an integer value is an atom, but a list is not. There's one where this is not strictly correct: string. According to AutoLisp a string is an atom, but you can split it using substr. In most other Lisps a string is a specific version of sequences, as are lists and arrays. To take the analogy further: a molecule would be similar to an array or a string (i.e. a rigid collection of atoms - the string being a collection of characters which are atomic), a list is less rigid (perhaps like a mixture instead of a molecule).

Posted
See a symbol as the container of data/code - it's like a name you give something so you can refer to it later.

 

Item is not actually a Lisp thing, it's a way of speaking in English to refer to one thing from a collection of things. We usually use it to refer to one position inside a list.

 

Atom is a Lisp thing which refers to data inside a symbol, where that data is an "atomic" value - i.e. it cannot be split into separate parts. E.g. an integer value is an atom, but a list is not. There's one where this is not strictly correct: string. According to AutoLisp a string is an atom, but you can split it using substr. In most other Lisps a string is a specific version of sequences, as are lists and arrays. To take the analogy further: a molecule would be similar to an array or a string (i.e. a rigid collection of atoms - the string being a collection of characters which are atomic), a list is less rigid (perhaps like a mixture instead of a molecule).

 

 

its all become more clearer now :D

Thanks

Shay

Posted

Here's taken from the autodesk exchange, all of the regular autolisp data types. Not symbols specifically but you can see how important they are, one of the major data types.

 

VLA-objects

 

Objects in a drawing can be represented as Visual LISP ActiveX® (VLA) objects, a data type introduced with Visual LISP. When working with ActiveX functions, you must refer to VLA-objects, not the ename pointer returned by functions such as entlast. For information on working with ActiveX objects, see Using ActiveX Objects with AutoLISP.

 

 

Symbols and Variables

 

 

AutoLISP uses symbols to refer to data. Symbol names are not case sensitive and may consist of any sequence of alphanumeric and notation characters, except the following:

 

Characters restricted from symbol names

(

(Open Parenthesis)

)

(Close Parenthesis)

.

(Period)

'

(Apostrophe)

"

(Quote Symbol)

;

(Semicolon)

 

 

A symbol name cannot consist only of numeric characters.

 

Technically, AutoLISP applications consist of either symbols or constant values, such as strings, reals, and integers. For the sake of clarity, this guide uses the term symbol to refer to a symbol name that stores static data, such as built-in and user-defined functions. The term variable is used to refer to a symbol name that stores program data. The following example uses the setq function to assign the string value "this is a string" to the str1 variable:

 

 

 

 

 

_$ (setq str1 "this is astring")"this is a string"

 

Help yourself and others who need to read your code. Choose meaningful names for your program symbols and variables.

 

 

File Descriptors

 

A file descriptor is a pointer to a file opened by the AutoLISP open function. The open function returns this pointer as an alphanumeric label. You supply the file descriptor as an argument to other AutoLISP functions that read or write to the file.

The following example opens the myinfo.dat file for reading. The open function returns the file descriptor:

_$ (setq file1 (open "c:\\myinfo.dat""r") )#

In this example, the file descriptor is stored in the file1variable.

Files remain open until you explicitly close them in your AutoLISP program. The close function closes a file. The following code closes the file whose file descriptor is stored in the file1 variable:

 

_$ (close file1)nil

 

 

 

 

Entity Names

 

An entity name is a numeric label assigned to objects in a drawing. It is actually a pointer into a file maintained by AutoCAD, and can be used to find the object's database record and its vectors (if they are displayed). This label can be referenced by AutoLISP functions to allow selection of objects for processing in various ways. Internally, AutoCAD refers to objects as entities.

The following example uses the entlast function to get the name of the last object entered into the drawing.

_$ (entlast)

Entity names assigned to objects in a drawing are only in effect during the current editing session. The next time you open the drawing, AutoCAD assigns new entity names to the objects. You can use an object's handle to refer to it from one editing session to another; see Entity Handles and Their Uses for information on using handles.

 

 

 

Selection Sets

 

Selection sets are groups of one or more objects (entities). You can interactively add objects to, or remove objects from, selection sets with AutoLISP routines.

The following example uses the ssget function to return a selection set containing all the objects in a drawing.

 

 

_$ (ssget "X") Lists

 

An AutoLISP list is a group of related values separated by spaces and enclosed in parentheses. Lists provide an efficient method of storing numerous related values. AutoCAD expresses 3D points as a list of three real numbers.

Examples of lists are (1.0 1.0 0.0), (“this” “that” “the other”), and (1 “ONE”).

 

 

 

Strings

 

A string is a group of characters surrounded by quotation marks. Within quoted strings the backslash (\) character allows control characters (or escape codes) to be included. When you explicitly use a quoted string in an AutoLISP expression, that value is known as a literal string or a string constant.

Examples of valid strings are “string 1” and “\nEnter first point:”.

 

 

 

Reals

 

A real is a number containing a decimal point. Numbers between -1 and 1 must contain a leading zero. Real numbers are stored in double-precision floating-point format, providing at least 14 significant digits of precision. Note that VLISP does not show you all the significant digits.

Reals can be expressed in scientific notation, which has an optional e or E followed by the exponent of the number (for example, 0.0000041 is the same as 4.1e-6). Numbers such as 3.1, 0.23, -56.123, and 21,000,000.0 are valid AutoLISP reals.

 

 

Integers

 

Integers are whole numbers that do not contain a decimal point. AutoLISP integers are 32-bit signed numbers with values ranging from +2,147,483,647 to -2,147,483,648. (Note, however, that the getint function only accepts 16-bit numbers ranging from +32767 to -32678.) When you explicitly use an integer in an AutoLISP expression, that value is known as a constant. Numbers such as 2, -56, and 1,200,196 are valid AutoLISP integers.

If you enter a number that is greater than the maximum integer allowed (resulting in integer overflow), AutoLISP converts the integer to a real number. However, if you perform an arithmetic operation on two valid integers, and the result is greater than the maximum allowable integer, the resulting number will be invalid. The following examples illustrate how AutoLISP handles integer overflow.

The largest positive integer value retains its specified value:

_$ 21474836472147483647

If you enter an integer that is greater than the largest allowable value, AutoLISP returns the value as a real:

_$ 2147483648 2.14748e+009

An arithmetic operation involving two valid integers, but resulting in integer overflow, produces an invalid result:

_$ (+ 2147483646 3)-2147483647

In this example the result is clearly invalid, as the addition of two positive numbers results in a negative number. But note how the following operation produces a valid result:

_$ (+ 2147483648 2)2.14748e+009

In this instance, AutoLISP converts 2147483648 to a valid real before adding 2 to the number. The result is a valid real.

The largest negative integer value retains its specified value:

_$ -2147483647-2147483647

If you enter a negative integer larger than the greatest allowable negative value, AutoLISP returns the value as a real:

_$ -2147483648-2.14748e+009

The following operation concludes successfully, because AutoLISP first converts the overflow negative integer to a valid real:

 

 

 

 

 

_$ (- -2147483648 1)-2.14748e+009 -----------------------------------------------------------------------------------------------------------------------

Just taken from the Autodesk exchange....simply a quick reference to be able to view all of the autolisp data types. Anyone can go read this on their own but at least now it's on one webpage :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...