Author Topic: Clearing Variables forcefully  (Read 3329 times)

0 Members and 1 Guest are viewing this topic.

Binky

  • Guest
Clearing Variables forcefully
« on: January 22, 2008, 10:45:37 AM »
Is there a way that I can get a variable that I created in a lisp routine out of memory while still inside the routine?  I ask this since I am having some difficulty with a routine I am writing.  I have the variable listed in the defun statement as a local variable.  as in I did this...

(defun c:whatever ( \ xyz)

Not being the most knowledgeable, but I believed that xyz would disappear once the routine ended successfully.  Turns out that it does not, I know this because I can type !xyz on the command line and get the list that I shoved in there.  That lingering information trips the routine when run a second time.


Guest

  • Guest
Re: Clearing Variables forcefully
« Reply #1 on: January 22, 2008, 10:47:53 AM »
Is there a way that I can get a variable that I created in a lisp routine out of memory while still inside the routine?  I ask this since I am having some difficulty with a routine I am writing.  I have the variable listed in the defun statement as a local variable.  as in I did this...

(defun c:whatever ( \ xyz)

Not being the most knowledgeable, but I believed that xyz would disappear once the routine ended successfully.  Turns out that it does not, I know this because I can type !xyz on the command line and get the list that I shoved in there.  That lingering information trips the routine when run a second time.

You've got your slash backwards.  It should be (defun c:whatever ( / xyz)

Didge

  • Bull Frog
  • Posts: 211
Re: Clearing Variables forcefully
« Reply #2 on: January 22, 2008, 11:30:18 AM »
Additionally, the forward slash in:  (defun c:whatever ( / xyz)
defines those variables as local to that particular function. Variables by the same name declared elsewhere, including the command line can contain other values.  Try experimenting with the following code:

Code: [Select]
(defun c:TEST (/ x y z)
  (setq x 10 y 20 z 30)
  (list x y z)
)

(setq x 90 y 90 z 90)
(c:test)
(list x y z)
Think Slow......

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Clearing Variables forcefully
« Reply #3 on: January 22, 2008, 12:17:15 PM »
Is there a way that I can get a variable that I created in a lisp routine out of memory while still inside the routine


(setq xyz nil)
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Clearing Variables forcefully
« Reply #4 on: January 22, 2008, 12:25:10 PM »
Keep in mind that if variable xyz ever enjoyed global scope it will continue to exist as a global until it is explicitly deleted, even if myFunction (now) sports it as a local.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Binky

  • Guest
Re: Clearing Variables forcefully
« Reply #5 on: January 22, 2008, 12:44:33 PM »
You've got your slash backwards.  It should be (defun c:whatever ( / xyz)

Figures,  :ugly:

(setq xyz nil)

Thought of that, at the time though (1am) I figured that I would simply be remaking the list with nil as an item in the list since it was being created and added to with 'cons' statements.  I just did some testing on the command line and it didn't, however now I am thinking that it should have.

Didge, that demonstrates what I thought should have happened and would have if I get my sense of direction figured out.

Keep in mind that if variable xyz ever enjoyed global scope it will continue to exist as a global until it is explicitly deleted, even if myFunction (now) sports it as a local.

If by that you mean global to the main function and any sub functions during the run but not to anything else after it is completed then I think we are thinking that same thing, at least that is what I meant when I said local earlier, I just reached for that word when I saw the variable still hang around getting more 'global' then I thought it should.

Thanks folks.
« Last Edit: January 22, 2008, 12:48:43 PM by Binky »

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Clearing Variables forcefully
« Reply #6 on: January 22, 2008, 02:03:50 PM »
I know that you believe you understand what you think I said, but I'm not sure you realize that what you heard is not what I meant.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Re: Clearing Variables forcefully
« Reply #7 on: January 22, 2008, 02:40:40 PM »
When in doubt close restart acad and try again!!  :-)
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright © 2016

Binky

  • Guest
Re: Clearing Variables forcefully
« Reply #8 on: January 22, 2008, 03:07:24 PM »
I know that you believe you understand what you think I said, but I'm not sure you realize that what you heard is not what I meant.

You mean I can't count of the voices in my head to interpret correctly?, Man, now who am I supposed to trust?

Guest

  • Guest
Re: Clearing Variables forcefully
« Reply #9 on: January 22, 2008, 03:17:12 PM »
I know that you believe you understand what you think I said, but I'm not sure you realize that what you heard is not what I meant.

You mean I can't count of the voices in my head to interpret correctly?, Man, now who am I supposed to trust?

The government??!?   :?

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Clearing Variables forcefully
« Reply #10 on: January 22, 2008, 08:42:19 PM »
If by that you mean global to the main function and any sub functions during the run but not to anything else after it is completed then I think we are thinking that same thing, at least that is what I meant when I said local earlier, I just reached for that word when I saw the variable still hang around getting more 'global' then I thought it should.
If a variable exists in global global scope before the execution of function x and said function does not alter said global variable it (said global) continues to enjoy it's former state, even after said function terminates.

Quote from: AutoCAD command line
Command: (setq myvar "W00t!")[Enter]
"W00t!"

Command: !myvar[Enter]
"W00t!"

Command: (defun foo1 ( / myvar ) (princ (strcat "myvar (local) = " (setq myvar "Just say no to w00t!")))(princ))[Enter]
FOO1

Command: (foo1)[Enter]
myvar (local) = Just say no to w00t!

Command: !myvar[Enter]
"W00t!"

Command: (defun foo2 ( ) (princ (strcat "myvar (global) = " (vl-princ-to-string myvar)))(princ))[Enter]
FOO2

Command: (foo2)[Enter]
myvar (global) = W00t!

Command: !myvar[Enter]
"W00t!"

Command: (defun foo3 ( ) (princ (strcat "myvar (global) = " (vl-princ-to-string (setq myvar nil))))(princ))[Enter]
FOO3

Command: (foo3)[Enter]
myvar (global) = nil

Command: !myvar[Enter]
nil

Command: (foo1)[Enter]
myvar (local) = Just say no to w00t!

Command: !myvar[Enter]
nil

Hope this helps illuminate.

:)
« Last Edit: January 23, 2008, 07:00:33 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst