TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Binky 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.
-
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)
-
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:
(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)
-
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)
-
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.
-
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.
-
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.
-
When in doubt close restart acad and try again!! :-)
-
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?
-
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??!? :?
-
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.
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.
:)