autolisp can't substract two integers

autolisp can't substract two integers

Anonymous
Not applicable
1,699 Views
14 Replies
Message 1 of 15

autolisp can't substract two integers

Anonymous
Not applicable

This one perplexes me.

 

If I run this, I get the expected result (12)

 

(setq value (+ 8 4))  

 

However, if I do this:

 

(setq value (- 8 4))  

 

I get this error message:

 

; error: bad function: 1

 

 

As a workaround I am using 

( setq value (+ 8 (* 4 -1)) )  

Any ideas?

 

 

thanks

 

0 Likes
Accepted solutions (1)
1,700 Views
14 Replies
Replies (14)
Message 2 of 15

cadffm
Consultant
Consultant

Start a new drawing, try it again.

Sebastian

Message 3 of 15

Anonymous
Not applicable

With a new drawing, substraction works fine. However, with existing drawings the error persists. Thank you.

0 Likes
Message 4 of 15

cadffm
Consultant
Consultant

After closing and re-opening this file still a problem ???

Please, share this file

Sebastian

Message 5 of 15

john.uhden
Mentor
Mentor

Have you tried an AUDIT on the mischievous files?

At the command prompt, what does !- return (for both the bads and the goods)?

Are the mischievous files from an older version such that some code you are loading loads say "this" versus "that" based on the version in which the drawing was last saved?  ACADVER won't tell you the version in which the file was saved, but there is an easy way to read the first 6 characters of a DWG file  to determine that.

How about if you save a "bad" drawing and reopen it?  Does the symptom disappear?  Or are you maybe saving as default to an older version?

John F. Uhden

Message 6 of 15

gcsjlewis
Collaborator
Collaborator

"value" is a command in autolisp.  So (setq value ....) will not work.  Try a different variable.  I use notepad++ when coding, and if you save the file as a .lsp, the variables will be become blue, it it is already defined.

Message 7 of 15

gcsjlewis
Collaborator
Collaborator

"value" is a command in autolisp/autocad.  So (setq value ....) will not work.  Try a different variable.  I use notepad++ when coding, and if you save the file as a .lsp, the variables will be become blue, it it is already defined.

Message 8 of 15

Kent1Cooper
Consultant
Consultant

@gcsjlewis wrote:

"value" is a command in autolisp/autocad.  .....


It's not listed in Help [2021], neither as an AutoCAD command nor system variable nor as an AutoLisp function.  Besides, if that were the problem, their first example wouldn't have worked.

Kent Cooper, AIA
Message 9 of 15

pbejse
Mentor
Mentor

@Anonymous wrote:
; error: bad function: 1

Any ideas?


Could it be that you somehow redefine "-" as something else within other lisp code

 

(setq  - 1);<--- somewhere  in any your lisp codes
(setq value (+ 8 4))
(setq value (- 8 4))

 

Which explains why it  works on a new drawing, until some other codes triggers the redefining of the symbol?

 

Message 10 of 15

vladimir_michl
Advisor
Advisor

Someone (some LISP code) has redefined your function '-.

 

You can simulate this (bad) behaviour e.g. with:

(defun - (a b)+(1))

 

Vladimir Michl, www.cadstudio.cz - www.cadforum.cz

Message 11 of 15

hak_vz
Advisor
Advisor

@gcsjlewis  

In N++ if you have language selected set on LISP it stands for Common LISP. It has something called accessor  functions and one of this is "VALUE"(that's why it is highlighted blue). 

For Autolisp I use this 

 

 

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.
Message 12 of 15

Anonymous
Not applicable

Hi, no, opening and closing the file does not solve the problem. I cannot share the file, it contains sensitive information.

0 Likes
Message 13 of 15

Anonymous
Not applicable
Accepted solution

You put me in the right track. I wasn't aware of the audit command, but when I read the docs about it I found a mention to the RECOVER command. That one did the trick. Thank you and thanks everybody for your collaboration.

0 Likes
Message 14 of 15

Anonymous
Not applicable

Interesting possibility. I 'll watch for that in future developments.  In this particular case, I reduced the source code to perform the substraction and nothing else. However, the error remained.

0 Likes
Message 15 of 15

john.uhden
Mentor
Mentor

@gcsjlewis 

value is not a command or a function in either my 2002 or my 2020.

But it appears that somewhere in the code he loading there is  (setq - 1).

Thus...

Command: (- 8 4)
; error: bad function: 1

We must all be careful not to use function symbol names as variables.

John F. Uhden