Lee Mac Posted December 22, 2009 Posted December 22, 2009 Do you guys localize ALL your variables in a function? It seems like a pain in the ass, especially for larger functions with a lot of counter variables and such. Yes, of couse. Except when you specifically need a variable to stay Global - to store settings etc. Just use the Checking function in the VLIDE to gather up all the variables in one click. Quote
alanjt Posted December 22, 2009 Posted December 22, 2009 Ok guys I'll give it a try. Thanks. Do you guys localize ALL your variables in a function? It seems like a pain in the ass, especially for larger functions with a lot of counter variables and such. Always. Good practice is the best practice. Quote
Lee Mac Posted December 22, 2009 Posted December 22, 2009 Unlocalised variables can cause some major problems when you are self-referencing variables, for example: (defun c:test ( ) (setq i 1) (repeat 10 (setq lst (cons (setq i (1+ i)) lst))) (print lst) (princ)) Run the above twice. Now localise its variables and run it twice. You can see the consequences of such things. Quote
alanjt Posted December 22, 2009 Posted December 22, 2009 Unlocalised variables can cause some major problems when you are self-referencing variables, for example: (defun c:test ( ) (setq i 1) (repeat 10 (setq lst (cons (setq i (1+ i)) lst))) (print lst) (princ)) Run the above twice. Now localise its variables and run it twice. You can see the consequences of such things. Excellent choice, cons is a great example. Quote
Lee Mac Posted December 22, 2009 Posted December 22, 2009 Excellent choice, cons is a great example. I know... I've been caught out by it many times Quote
muthu123 Posted December 23, 2009 Posted December 23, 2009 This may be more robust for you (defun c:test (/ v-move i ss selBlock SelnoBlock ent trck ) (defun v-move (ss p1 p2 / i ent) (vl-load-com) (setq i -1) (while (setq ent (ssname ss (setq i (1+ i)))) (vla-move (vlax-ename->vla-object ent) (vlax-3D-point p1) (vlax-3D-point p2))) ss) (if (setq i -1 ss (ssget "_:L")) (progn (setq SelBlock (ssadd) SelNoblock (ssadd)) (while (setq ent (ssname ss (setq i (1+ i)))) (if (assoc 66 (entget ent)) (ssadd ent selblock) (ssadd ent selnoblock))) (if (not (zerop (sslength selnoblock))) (progn (setq trck (entmakex '((0 . "POINT") (10 0 0 0)))) (sssetfirst nil selnoblock) (c:kti_archt_move) (if (not (zerop (sslength selblock))) (v-move selblock '(0 0 0) (cdr (assoc 10 (entget trck))))) (entdel trck)) (command "_.move" selblock "" pause pause)))) (princ)) { untested } Dear Lee, I need your help so much to learn v-lisp. 1. why you used always the command "_.move" "_:L" instead of "move" and "L". Can you explain clearly the difference? 2. Can you explain about error trapping? and how we can catch if the user press the "esc" key while execution of the program? In this case, how the error trap will help to re-set the default settings such as osnap, etc.. 3. How you learn V-lisp or through which source? can you give me some of your tested codes? and give me some link or reference books to learn v-lisp? 4.I have seen some of your codes in which you have used the combination of mapcar,function and lambda. What is the purpose and how it works? I used only the mapcar and lambda.. 5.I have to know the effective list handling procedure. So post your codes regarding this issue. 6. Is any way to find and put the local variables? I will post something later. Thank you and help me lee. Quote
Lee Mac Posted December 23, 2009 Posted December 23, 2009 1. why you used always the command "_.move" "_:L" instead of "move" and "L". Can you explain clearly the difference? "_" is language compatibility "." uses the undefined function http://www.cadforum.cz/cadforum_en/qaID.asp?tip=2425 2. Can you explain about error trapping? and how we can catch if the user press the "esc" key while execution of the program? In this case, how the error trap will help to re-set the default settings such as osnap, etc.. http://www.afralisp.net/lispa/lisp6.htm 3. How you learn V-lisp or through which source? can you give me some of your tested codes? and give me some link or reference books to learn v-lisp? To be honest, I learnt pretty much all of my Visual LISP through the forums, and also from the Visual LISP Editor Help files. 4.I have seen some of your codes in which you have used the combination of mapcar,function and lambda. What is the purpose and how it works? I used only the mapcar and lambda.. (setq lst '(1 2 3)) (mapcar '(lambda (x) (nth x lst)) '(0 2)) Is the same, but slower than@ (setq lst '(1 2 3)) (mapcar (function (lambda (x) (nth x lst))) '(0 2)) Its just like doing this: (setq lst (quote (1 2 3))) Instead of (setq lst '(1 2 3)) 5.I have to know the effective list handling procedure. So post your codes regarding this issue. http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node1.html 6. Is any way to find and put the local variables? Yes, read the help file on "defun". Also, look into the Checking feature in the Visual LISP Editor. 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.