ready2goriding Posted April 15, 2010 Share Posted April 15, 2010 After a little studying, I have written my first Lisp! I thought I would post it here for some comedy. I could not think of anything constructive to do at the time, so it basically asked the user for 3 points, forms an arc, then draws a line across the bottom. I have became very intrigued with these lately- maybe the next one will be better! Code: (defun c:zzx () (setq a (getpoint "\nfirst point ")) (setq b (getpoint "\nmidpoint ")) (setq c (getpoint "\nlast point ")) (command "arc" a b c) (command "line" c a"") (princ) ) ;end Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted April 15, 2010 Share Posted April 15, 2010 After a little studying, I have written my first Lisp! I thought I would post it here for some comedy. I could not think of anything constructive to do at the time, so it basically asked the user for 3 points, forms an arc, then draws a line across the bottom. I have became very intrigued with these lately- maybe the next one will be better! Code: (defun c:zzx () (setq a (getpoint "\nfirst point ")) (setq b (getpoint "\nmidpoint ")) (setq c (getpoint "\nlast point ")) (command "arc" a b c) (command "line" c a"") (princ) ) ;end That's how you learn by jumping into it. Keep it up. Do not forget to declare your variables as shown below. (defun c:zzx ([color=Red]/ a b c[/color]) (setq a (getpoint "\nfirst point ")) (setq b (getpoint "\nmidpoint ")) (setq c (getpoint "\nlast point ")) (command "arc" a b c) (command "line" c a"") (princ) ) ;end Quote Link to comment Share on other sites More sharing options...
ready2goriding Posted April 15, 2010 Author Share Posted April 15, 2010 That's how you learn by jumping into it.Keep it up. Do not forget to declare your variables as shown below. (defun c:zzx ([color=red]/ a b c[/color]) (setq a (getpoint "\nfirst point ")) (setq b (getpoint "\nmidpoint ")) (setq c (getpoint "\nlast point ")) (command "arc" a b c) (command "line" c a"") (princ) ) ;end Thanks for the encouragement! It is a lot of info to take in! I will learn more about declaring variables. I think that my present setup is Global... seemed easier at the time... Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 15, 2010 Share Posted April 15, 2010 To account for language differences, redefined commands, osnaps, syntax similarity and missed picks... (defun c:zzx (/ a b c) (and (setq a (getpoint "\nSpecify first point: ")) (setq b (getpoint a "\nSpecify midpoint: ")) (setq c (getpoint b "\nSpecify last point: ")) (progn (command "_.arc" "_non" a "_non" b "_non" c) (command "_.line" "_non" c "_non" a "") ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
ready2goriding Posted April 15, 2010 Author Share Posted April 15, 2010 To account for language differences, redefined commands, osnaps, syntax similarity and missed picks... (defun c:zzx (/ a b c) (and (setq a (getpoint "\nSpecify first point: ")) (setq b (getpoint a "\nSpecify midpoint: ")) (setq c (getpoint b "\nSpecify last point: ")) (progn (command "_.arc" "_non" a "_non" b "_non" c) (command "_.line" "_non" c "_non" a "") ) ) (princ) ) I see. By declaring the variables, they will always remain the same in this particular routine? I think? Thank you, doug Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted April 15, 2010 Share Posted April 15, 2010 It is good to have your variables global when you are in the testing stage of your program, Then you can test by: Command: !a (3.8045 3.64791 0.0) To avoid having these values interfere with other programs using the same variable, Then you should declare them local. When the program completes, Then you would have: Command: !a nil Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 15, 2010 Share Posted April 15, 2010 I see. By declaring the variables, they will always remain the same in this particular routine? I think?Thank you, doug If the variables are localized, then the variable will be nil when the routine ends. If left undeclared, one has the possibility of hundreds of assigned variable within a session (very messy). eg. (variables not localized) (defun c:Test (/) (and (setq a (getreal "\nNumber: ")) (setq lst (cons a lst)) (setq b (getreal "\nNumber: ")) (setq lst (cons b lst)) (print lst) ) (princ) ) result: Command: test Number: 1 Number: 2 (2.0 1.0) Command: Command: TEST Number: 3 Number: 4 (4.0 3.0 2.0 1.0) eg. (variables localized) (defun c:Test (/ a lst b) (and (setq a (getreal "\nNumber: ")) (setq lst (cons a lst)) (setq b (getreal "\nNumber: ")) (setq lst (cons b lst)) (print lst) ) (princ) ) result: Command: test Number: 4 Number: 5 (5.0 4.0) Command: Command: TEST Number: 9 Number: 8 (8.0 9.0) Command: Adding items to a list is just a really good example that I like to use. Quote Link to comment Share on other sites More sharing options...
ready2goriding Posted April 15, 2010 Author Share Posted April 15, 2010 Ok, I'm starting to see the light! Being able to check variables is good for debugging, then declare them and save trouble later on... Thanks guys, I have a lot to learn. Quote Link to comment Share on other sites More sharing options...
The Buzzard Posted April 15, 2010 Share Posted April 15, 2010 Ok, I'm starting to see the light! Being able to check variables is good for debugging, then declare them and save trouble later on...Thanks guys, I have a lot to learn. That's great. One thing that is in your favor is that you are willing to make the attempt. Do not be afraid to make mistakes. That is how you also learn. You also have in your favor a great site to come for help when you are stuck. Quote Link to comment Share on other sites More sharing options...
ready2goriding Posted April 16, 2010 Author Share Posted April 16, 2010 Two great points. I am making plenty of mistakes, but so far I have been able to find and correct them... I'm sure that I will be on here crying for help soon though! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 16, 2010 Share Posted April 16, 2010 It has pretty much been explained, but here is an FAQ I wrote a while back: http://www.cadtutor.net/forum/showpost.php?p=265649&postcount=4 It needs a bit of work, but might help. Quote Link to comment Share on other sites More sharing options...
ready2goriding Posted April 16, 2010 Author Share Posted April 16, 2010 It has pretty much been explained, but here is an FAQ I wrote a while back: http://www.cadtutor.net/forum/showpost.php?p=265649&postcount=4 It needs a bit of work, but might help. That gives me more details and a better understanding! I will be re-reading it many more times. Thanks, Lee! FWIW- Reading your lisp posts is why I got interested in trying to learn more about lisping, so thanks to you twice! doug Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 16, 2010 Share Posted April 16, 2010 You're very welcome Doug Quote Link to comment Share on other sites More sharing options...
muthu123 Posted April 18, 2010 Share Posted April 18, 2010 To account for language differences, redefined commands, osnaps, syntax similarity and missed picks... (defun c:zzx (/ a b c) (and (setq a (getpoint "\nSpecify first point: ")) (setq b (getpoint a "\nSpecify midpoint: ")) (setq c (getpoint b "\nSpecify last point: ")) (progn (command "_.arc" "_non" a "_non" b "_non" c) (command "_.line" "_non" c "_non" a "") ) ) (princ) ) Dear what is the use of "_non" ? Please explain in detail. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 18, 2010 Share Posted April 18, 2010 "_non" or "_none" means to ignore all ObjectSnaps for the next input. Quote Link to comment Share on other sites More sharing options...
muthu123 Posted April 18, 2010 Share Posted April 18, 2010 "_non" or "_none" means to ignore all ObjectSnaps for the next input. Dear lee, Thanks. I posted one thread that how to copy folder in VLISP? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 18, 2010 Share Posted April 18, 2010 You're welcome Muthu. Quote Link to comment Share on other sites More sharing options...
ready2goriding Posted April 19, 2010 Author Share Posted April 19, 2010 "_non" or "_none" means to ignore all ObjectSnaps for the next input. I deliberately tried to "confuse" my current lisp by having it snap to an improper point. I then updated the routine with this advice. It works well, but I forgot to include the underscore. Is the underscore important? I can't tell a difference between the functions of "non" or "_non"? I hate being the rookie... doug Quote Link to comment Share on other sites More sharing options...
alanjt Posted April 19, 2010 Share Posted April 19, 2010 I deliberately tried to "confuse" my current lisp by having it snap to an improper point. I then updated the routine with this advice. It works well, but I forgot to include the underscore. Is the underscore important? I can't tell a difference between the functions of "non" or "_non"? I hate being the rookie... doug The underscore will allow it to work with non-english version. Similarly, the period will use the core of the command instead of a possible redefining of it. eg. (command "_.line" "_non" p1 "_non" p2) Quote Link to comment Share on other sites More sharing options...
ready2goriding Posted April 19, 2010 Author Share Posted April 19, 2010 Thank you, I will adjust my programming accordingly! Quote Link to comment Share on other sites More sharing options...
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.