Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

autolisp can't substract two integers

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
Anonymous
1342 Views, 14 Replies

autolisp can't substract two integers

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

 

14 REPLIES 14
Message 2 of 15
cadffm
in reply to: Anonymous

Start a new drawing, try it again.

Sebastian

Message 3 of 15
Anonymous
in reply to: cadffm

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

Message 4 of 15
cadffm
in reply to: Anonymous

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

Please, share this file

Sebastian

Message 5 of 15
john.uhden
in reply to: Anonymous

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
in reply to: Anonymous

"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
in reply to: Anonymous

"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
in reply to: gcsjlewis


@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
in reply to: Anonymous


@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
in reply to: Anonymous

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
in reply to: gcsjlewis

@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
in reply to: cadffm

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

Message 13 of 15
Anonymous
in reply to: john.uhden

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.

Message 14 of 15
Anonymous
in reply to: pbejse

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.

Message 15 of 15
john.uhden
in reply to: gcsjlewis

@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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report