Author Topic: Is there a way to collect all variables from the code?  (Read 2430 times)

0 Members and 1 Guest are viewing this topic.

HasanCAD

  • Swamp Rat
  • Posts: 1422
Is there a way to collect all variables from the code?
« on: February 05, 2013, 01:19:05 AM »
Should we collect variables from the code manually or there is better way?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Is there a way to collect all variables from the code?
« Reply #1 on: February 05, 2013, 04:04:01 AM »
Well if you mean you want to figure out which variables your code leaves as globals, then try this tut from Lee Mac: http://www.lee-mac.com/quicklocalising.html

If you want to figure out all the variables from the code (local or not), then you could remove the local declarations from all the defuns first and then go through that VLIDE check. Just remember to re-localize them, else you could get lots of errors.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.


HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Is there a way to collect all variables from the code?
« Reply #3 on: February 05, 2013, 05:43:35 AM »
Well if you mean you want to figure out which variables your code leaves as globals, then try this tut from Lee Mac: http://www.lee-mac.com/quicklocalising.html

If you want to figure out all the variables from the code (local or not), then you could remove the local declarations from all the defuns first and then go through that VLIDE check. Just remember to re-localize them, else you could get lots of errors.
Thanx irneb

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Is there a way to collect all variables from the code?
« Reply #4 on: February 05, 2013, 07:36:30 AM »
I use this from: R. Robert Bell, MCSE
(defun C:Leak (/ lVars orgAtoms) ...
Just be careful of using such all the time. You could easily be clearing some global variable of some totally different piece of code (which you don't know about or forgot about or it's coming in from something else) that should have been left as is. Another issue using this "Clear Globals to NIL" idea is if you reuse that function inside another, it's quite possible to have naming conflicts which would then clear the calling function's local vars instead of the called function's global vars. Not saying you should not use this, but just be wary of errors which could come about because of it.

My advise is to list which variables are (still) global from your function then modify your function to localize them. It's the least problematic in the long run - especially with a Dynamic Scoped language like AutoLisp.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Is there a way to collect all variables from the code?
« Reply #5 on: February 05, 2013, 07:54:45 AM »
I use this from: R. Robert Bell, MCSE
(defun C:Leak (/ lVars orgAtoms) ...
Just be careful of using such all the time. You could easily be clearing some global variable of some totally different piece of code (which you don't know about or forgot about or it's coming in from something else) that should have been left as is. Another issue using this "Clear Globals to NIL" idea is if you reuse that function inside another, it's quite possible to have naming conflicts which would then clear the calling function's local vars instead of the called function's global vars. Not saying you should not use this, but just be wary of errors which could come about because of it.

My advise is to list which variables are (still) global from your function then modify your function to localize them. It's the least problematic in the long run - especially with a Dynamic Scoped language like AutoLisp.
Thanks for answer, I use "C:Leak" only for rough work, while I do the final check with VLIDE during compilation .

Marco

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: Is there a way to collect all variables from the code?
« Reply #6 on: February 05, 2013, 09:17:23 PM »
I often use lisplink to write the lsp code.
It has such function



but it also has some bug, like it will take "pi" or "1e3" as local variable, so it should be noticed.
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Is there a way to collect all variables from the code?
« Reply #7 on: February 06, 2013, 12:01:25 AM »
Thanks nice one, is it possible to modify LispLink's list of global / default symbols? Perhaps then it might function properly in all cases. Or someone could go and write a Python addon for Notepad++ to do the same there  ;)
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

qjchen

  • Bull Frog
  • Posts: 285
  • Best wishes to all
Re: Is there a way to collect all variables from the code?
« Reply #8 on: February 06, 2013, 03:41:10 AM »
Thanks nice one, is it possible to modify LispLink's list of global / default symbols? Perhaps then it might function properly in all cases. Or someone could go and write a Python addon for Notepad++ to do the same there  ;)

Hi, irneb, do you mean the syntax.dat in the installed directory?
http://qjchen.mjtd.com
My blog http://chenqj.blogspot.com (Chinese, can be translate into English)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Is there a way to collect all variables from the code?
« Reply #9 on: February 06, 2013, 04:19:15 AM »
Hi, irneb, do you mean the syntax.dat in the installed directory?
Don't know, perhaps that might help. I've never used LispLink, but I imagine such things must be customizable.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.