Jump to content

New Lisp Lover!


ready2goriding

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

  • ready2goriding

    9

  • Lee Mac

    5

  • alanjt

    4

  • The Buzzard

    3

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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! :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

"_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?

Link to comment
Share on other sites

"_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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...