Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Illegal Variable Names

john.uhden
Mentor

Illegal Variable Names

john.uhden
Mentor
Mentor

I guess I never studied this before (in 40 years), but I stumbled on AutoLisp disliking a variable named A'.

I'm sure there are plenty others (names), but I thought I would just pass this along as a warning to those who like to use unique variable names.

John F. Uhden

0 Likes
Reply
Accepted solutions (2)
1,462 Views
10 Replies
Replies (10)

hak_vz
Advisor
Advisor
Command: (setq  c'  100)
100
Command: (+  c  100)
200
Command: (+  c'  100)
200
Command: !c'
'_>

Variable name is looked without quote

 

Command: (setq  a'b  50)
; error: syntax error

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

dlanorh
Advisor
Advisor

I always run anything i'm not sure of through snvalid

 

 

I am not one of the robots you're looking for

0 Likes

devitg
Advisor
Advisor
Accepted solution

@john.uhden  if you would use VLIDE as a LISP editor , you will notice that such char to be painted as control Char, as to be not allowed  

 

devitg_0-1598364864277.png

the brown painted is not allowed  

 

You can use all the shift+number 

 

(setq a!@#$%^&* 100)
(+ a!@#$%^&* 4)

104

(setq a:{}][~`® 400)

400

 

Also a especial, like ® from alt+0174 

 and math operator too

 

 

(setq a!@#$%^&*+-?/\ 500)
(+ a!@#$%^&*+-?/\ 4)

500
504

 

also it

 

(setq a!@#$%^&*+-?/\<>:: 500)
(+ a!@#$%^&*+-?/\<>:: 7)

500
507

 

it seem to be that ' " ; are not allow. 

 

 

 

 

 

 

 

john.uhden
Mentor
Mentor
Hmmm. I wonder if Textpad has such a feature.
I doubt it though because we use apostrophes legally as well.

John F. Uhden

0 Likes

devitg
Advisor
Advisor

@john.uhden , The one million question, why not to use VLIDE? 

 

 

0 Likes

Sea-Haven
Mentor
Mentor

If Johns like me when VLIDE locks up your Autocad its a pain all the resets are locked out CTRL ALT DEL is only way unless you know some secret to truly doing a reset of vlide. Next time I have code that does it will send it to you.

 

I tend to write and test as I go.

0 Likes

martti.halminen
Collaborator
Collaborator
Accepted solution

What is happening here is that a single quote is not an ordinary character in Lisp, it is defined as a reader macro.

 

The Lisp user interface runs a so-called read-eval-print loop, often abbreviated as REPL. It is essentially just

(loop (print (eval (read))))

- with prompting, error handling etc. added.

 

So when you call READ, it expands all the reader macroes before giving the result to EVAL.

 

The behaviour of ' is to convert the next Lisp item into a call to the QUOTE function:

(read "(setq c' 100)")   ->  (SETQ C (QUOTE 100))

 

This happens with no regard to the syntactic correctness, EVAL has to handle that. So

 

$ (read "(setq a'b 50)")
(SETQ A (QUOTE B) 50)

- which doesn't make sense so you get an error in EVAL.

 

The previous was all normal Lisp behaviour, you'd get similar behaviour on any Lisp.

 

A somewhat similar thing happens with a period, but that is strictly an Autodesk oddity:

 

(setq a.b 42)  doesn't cause any error reports, but behaves rather differently than most users would expect.

 

In Common Lisp that would be fully legal, setting the value of the variable A.B, but in AutoLISP, that sets the value of A instead.

 

_$ (setq a 'something)
SOMETHING
_$ (setq a.b 42)
42
_$ a.b
42
_$ a
42
_$ (read "a.b")
A

So what is happening, when reading a symbol name, the AutoLISP reader stops reading when encountering a period, uses what was read so far as the result and ignores the rest, with no warning whatsoever.

- creates rather interesting bugs if you are not familiar with this behaviour.

 

As these characters are fully legal elsewhere in a program, a programming environment can't catch these unless it also runs a full syntactic analysis.

 

devitg
Advisor
Advisor

@Sea-Haven I always do test and try line by line. 

I had such a problem with some command as Explode, please send me such LISP . 

Regards

 

0 Likes

hak_vz
Advisor
Advisor

@martti.halminenThank you for detail explanation

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes

john.uhden
Mentor
Mentor

@devitg :

That's comforting to know.  Thanks for all that effort.

BTW, I use 2pi and 1/2pi and 3/2pi a lot because I don't want to keep repeating operations and typing.

John F. Uhden

0 Likes