Lee Mac Posted December 28, 2008 Posted December 28, 2008 Hi Guys, Sorry for the plethora of Thread I've created today, but I have a sudden influx of questions that, if answered, would fill various holes in my knowledge of LISP. My question is this: If I have a subroutine, say for creating a list, and I set the list to a variable say "a", do I localise this variable in the sub-routine, and, if I do, will it still be available in the main routine? i.e. (defun c:test () (testa) (alert a) (princ) ) ;_ end defun (defun testa (/ [b][color=Red]a[/color][/b]) (setq a (getstring t)) ) ;_ end defun Should I localise the highlighted variable, and, if I do, can I still use it in the main routine as shown? Also, should I also localise it in the main routine? Quote
ASMI Posted December 28, 2008 Posted December 28, 2008 (defun c:test2 (/ b) (setq b(testa)) (alert b) (princ) ) ;_ end defun or (defun c:test3 () (alert(testa)) (princ) ) ;_ end defun Quote
Lee Mac Posted January 1, 2009 Author Posted January 1, 2009 Thanks for your help ASMI, that is a bit of a work-around, and works well. After a bit of experimentation, I have found that if you have a sub-routine with some variables that are then used in the main-routine, these variables should be localised in the main-routine and not the sub-routine for them to hold their values. Otherwise, their values are set to nil after the sub-routine has completed. Quote
ASMI Posted January 2, 2009 Posted January 2, 2009 After a bit of experimentation, I have found that if you have a sub-routine with some variables that are then used in the main-routine, these variables should be localised in the main-routine and not the sub-routine for them to hold their values. Yes. Place subfunction inside main function to make it local (for LISP correctly to speak function). (defun c:mainfun(/ [color="SeaGreen"][b]a[/b][/color]) (defun subfun() (setq [color="SeaGreen"][b]a[/b][/color] ...) ); end subfun ... (princ) ); end c:maifun Quote
Lee Mac Posted January 2, 2009 Author Posted January 2, 2009 for LISP correctly to speak function... Haha, I've really gotta learn the LISP lingo Thanks ASMI, help appreciated as always 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.