AIberto Posted August 18, 2015 Posted August 18, 2015 Dear all Before appload lisp (fas ,vlx ) , record global variables. (can use "atoms-family" func ?) After appload lisp (fas, vlx) , record global variables. Than ,get a list of global variables. Is this possible? I've done a little bit of searching for this, but have not found what I've needed. but would like to know if anyone has come up with a lisp or other solution. BTW I see an article "A Shortcut to Localising Variables" by Lee, http://www.lee-mac.com/quicklocalising.html I feel vlide IDE is not reliable , A test . Simple code (defun c:test (/ fun1 fun2 s1 s2 d g) (defun fun1 (p / a b c) (setq a 10) (setq b 20) (setq c (+ a b)) (setq d (* p c)) d );_end_defun_fun1 (defun fun2 (/ e f ) (fun1 3) (setq e 2) (setq f 10) (setq g (* d (* e f))) g );_end_defun_fun2 (fun2) (setq s1 20) (setq s2 (* s1 g)) s2 );_end defun use vlide check . [CHECKING TEXT <Untitled-0> loading...] . ; warning: local variable used as function: FUN2 ; === Top statistic: ; Global variables: (D G) ; Function definition (with number of arguments): ((FUN2 . 0) (FUN1 . 1) (C:TEST . 0)) ; Check done. My doubt is why "D" and "G" is global variables ? Quote
tombu Posted August 18, 2015 Posted August 18, 2015 Wouldn't this fix everything? (defun c:test (/ fun1 fun2 s1 s2) (defun fun1 (p / a b c d) (setq a 10) (setq b 20) (setq c (+ a b)) (setq d (* p c)) d );_end_defun_fun1 (defun fun2 (/ e f g) (fun1 3) (setq e 2) (setq f 10) (setq g (* d (* e f))) g );_end_defun_fun2 (fun2) (setq s1 20) (setq s2 (* s1 g)) s2 );_end defun Quote
AIberto Posted August 18, 2015 Author Posted August 18, 2015 Wouldn't this fix everything? (defun c:test (/ fun1 fun2 s1 s2) (defun fun1 (p / a b c d) (setq a 10) (setq b 20) (setq c (+ a b)) (setq d (* p c)) d );_end_defun_fun1 (defun fun2 (/ e f g) (fun1 3) (setq e 2) (setq f 10) (setq g (* d (* e f))) g );_end_defun_fun2 (fun2) (setq s1 20) (setq s2 (* s1 g)) s2 );_end defun What do you mean? Quote
tombu Posted August 18, 2015 Posted August 18, 2015 What do you mean? I just put the local variables inside the functions that used them. With vlide check do D &G still show up as global variables? Quote
AIberto Posted August 18, 2015 Author Posted August 18, 2015 I just put the local variables inside the functions that used them. With vlide check do D &G still show up as global variables? See this (defun main (/ v1 v3 subfun1 subfun2) (setq v1 (......)) (defun subfun1(/ v2) (setq v2 (.....)) (setq v3 (......)) ...... );;end_defun_subfun1 (defun subfun2(/ subb v4 v5 v6) (defun subb(/ a b c) (setq a (...)) (setq b (...)) (setq c (*(atoi v6) 10)) );;end_defun_subb (setq v4 (.....)) (setq v5 (*(atoi v3) 13)) (setq v6 (.....)) (subb) );;end_defun_subfun2 );;end_defun_main This is just a very simple example , Quote
AIberto Posted August 18, 2015 Author Posted August 18, 2015 I just put the local variables inside the functions that used them. With vlide check do D &G still show up as global variables? and this Localising Variables is difficult. gccx.lsp Quote
Lee Mac Posted August 18, 2015 Posted August 18, 2015 Wouldn't this fix everything? (defun c:test (/ fun1 fun2 s1 s2) (defun fun1 (p / a b c d) (setq a 10) (setq b 20) (setq c (+ a b)) (setq d (* p c)) d );_end_defun_fun1 (defun fun2 (/ e f g) (fun1 3) (setq e 2) (setq f 10) (setq g (* d (* e f))) g );_end_defun_fun2 (fun2) (setq s1 20) (setq s2 (* s1 g)) s2 );_end defun Variable 'd' will be nil in (fun2) as it is declared local to (fun1). Cross-reference thread: http://www.theswamp.org/index.php?topic=49967.0 Quote
tombu Posted August 18, 2015 Posted August 18, 2015 (edited) Variable 'd' will be nil in (fun2) as it is declared local to (fun1). Cross-reference thread: http://www.theswamp.org/index.php?topic=49967.0 Ok, tested it this time: (defun c:test (/ fun1 fun2) (defun fun1 (p / a b c d) (setq a 10 b 20 c (+ a b) d (* p c) ) );_end_defun_fun1 (defun fun2 (/ e f g) (setq e 2 f 10 g (* (fun1 3) (* e f)) ) );_end_defun_fun2 (*(fun2)20) );_end defun Cleaned up and removed s1 & s2 since as local variables they wouldn't be available afterwards. Returns 36000 Edited August 18, 2015 by tombu Removed d from fun2 Quote
tombu Posted August 18, 2015 Posted August 18, 2015 Creating local variables are much easier while creating the code. Every time you use a variable add it to the defun if you want it to be local. Don't forget you can use the output of a function without setting it to a variable first. Quote
AIberto Posted August 18, 2015 Author Posted August 18, 2015 Creating local variables are much easier while creating the code. Every time you use a variable add it to the defun if you want it to be local. Don't forget you can use the output of a function without setting it to a variable first. Dear tombu ,is a way to get a list of global variables ? Quote
tombu Posted August 18, 2015 Posted August 18, 2015 Dear tombu ,is a way to get a list of global variables ? Try: http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/list-global-variables-not-used-by-autocad-in-autocad-drawing/td-p/2149213 Quote
AIberto Posted August 18, 2015 Author Posted August 18, 2015 Try: http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/list-global-variables-not-used-by-autocad-in-autocad-drawing/td-p/2149213 Thank you tombu ,I will have a look. Quote
AIberto Posted August 19, 2015 Author Posted August 19, 2015 Try: http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/list-global-variables-not-used-by-autocad-in-autocad-drawing/td-p/2149213 *Tony Tanzillo wrote: You can't do what you ask because there is no way to know learn what symbols are used and what symbols are not used. If it's about local verses global variables, you can run a 'diff' on two copies of the list that's returned by the (atoms-family) function to see what symbols were added to it after you run a function the first time. Something like this: (defun atoms-family-diff ( func / oldlist newlist difflist ) (setq oldlist (atoms-family 0)) (vl-catch-all-apply func nil) (setq newlist (atoms-family 0)) (foreach sym newlist (if (not (member sym oldlist)) (setq difflist (cons sym difflist)) ) ) (vl-remove 'oldlist difflist) ) ;; Test function: (defun foobar ( / local1 ) (setq foobar_01 1) (setq foobar_02 2) (setq foobar_03 3) (setq local1 "hello") (princ) ) Command: (atoms-family-diff 'foobar) (FOOBAR_01 FOOBAR_02 FOOBAR_03) ;; Test function: (defun test ( / fun1 fun2 s1 s2 d g) (defun fun1 (p / a b c) (setq a 10) (setq b 20) (setq c (+ a b)) (setq d (* p c)) d );_end_defun_fun1 (defun fun2 (/ e f ) (fun1 3) (setq e 2) (setq f 10) (setq g (* d (* e f))) g );_end_defun_fun2 (fun2) (setq s1 20) (setq s2 (* s1 g)) s2 );_end defun ; Command: (atoms-family-diff 'test) returns--> nil Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.