Jump to content

Recommended Posts

Posted

I would like to learn how to write some lisp programs and I have some experience programing CNC machines. Not simply M and G code programing but real elaborate programs using High level programing and parametric programing. So I know how to write a program for the CNC that says " IF parameter1000 is Greater than or equal to perameter1001 than goto...." Or how to call sub routines and other stuff like that.

So what I am wondering is if someone here can help me to bridge the gap between CNC and Lisp programing. So what would be the Lisp equivalent to such statements like the following....

 

(If (P1000 GE P1001)Goto N100)----

(If (p1000 GE P1001)P1002=P1003+P1004)------

(PCALL 300)-CALLS SUBROUTINE 300-----

(IF (P1000 GE P1001)PCALL 300 ELSE PCALL 200)

This is just a start to me learning but I thought that if I could relate it to something I already know it might be easier. So any help would be appreciated. Thanks for your help.

  • Replies 46
  • Created
  • Last Reply

Top Posters In This Topic

  • TheNewGuy

    21

  • Lee Mac

    19

  • Se7en

    4

  • Commandobill

    2

Posted

IF statements are still used in LISP programming, such as:

 

(if (this is true)
  .. do this...
  .. else do this...
)

 

Or with progn to wrap multiple statements:

 

(if (this is true)
 (progn
   .. do this..
   .. and this..
 )  ; end Progn
 .. else do this..
)  ; end If

 

or with multiple progn :

 

(if (this is true)
 (progn
   .. do this..
   .. and this..
 )  ; end Progn
 (progn
 .. else do this..
 .. and this..
 .. and this..
 ) ; end progn
)  ; end If

 

 

As for calling sub-functions:

 

A sub-function is defined as follows:

 

(defun mysub (arg1 arg2 / var1 var2)
  .. do something..
)

 

Using "defun" as opposed to "defun c:", where arg1 & arg2 are the arguments needed to run it, and var1 & var2 are the local variables.

 

And so to call it:

 

(mysub x y)

 

Where x & y are values for the arguments arg1 & arg2.

 

Hope this makes some sense to you, if i have missed something, just ask :)

 

Lee

Posted

Ok that helps thank you.

 

So in CNC I would simply say

 

(P100=5)

 

IN LISP i WOULD SAY...

 

(setq (P=5) is that correct?

Posted

If you are using P as a variable name and 5 as its value, then in LISP:

 

(setq P 5)

Tbh, with questions like these, you are far better off going to a tutorial site to learn things - more will be covered.

 

Check out Jeffery Sanders - just google Jeffery P sanders LISP>

Posted
...you are far better off going to a tutorial site to learn things - more will be covered.

 

Check out Jeffery Sanders - just google Jeffery P sanders LISP>

 

I say skip the tutorial sites and go read the SICP book; spend a month in the beginning and save yourself a year in the end --Reading that book will save you a lot of time when learning different flavors of high level languages and trying to interpret methods and means later-.

 

Trust me!

 

[ http://mitpress.mit.edu/sicp/full-text/book/book.html ]

Posted

Nice! an online book. I will definitely read that. Thanks for all your help. (I can't believe you have only been programing acad for 9 months.) That is amazing! Take care.

Posted
Nice! an online book. I will definitely read that.

...

That book is for the Scheme language NOT AutoLisp. It is meant as a teaching aid.

 

However the Scheme language resembles the AutoLisp dialect very closely so switching from Scheme to AutoLisp will be easy.

Posted

Oh... OK.. But the site jeffery sanders is about lisp. right? Also I found a lisp program from that site that will write a Lisp for you based on your answers to some questions, but I can't get it to work. Are you familiar with such a lisp? I though I could use it to make some simple lisp programs and then I could look at the code and learn from there. The program is called, Make_lsp.lsp ever heard of it?

Posted

Haven't heard of it, but I would recommend just learning LISP from the bottom up - not using a LISP to generate one for you.

 

Just look at examples on this site and also take a look at the book that Se7en recommends - i could learn a lot from it too :)

Posted

*blink-blink* *gack* no (I dont even want to see anything like that...it sounds horrible!). Please, trust me there can not be a `Make_lsp.lsp' that you would want. Something like that would be an abomination of programing and only hurt you.

 

Seriously, it sounds like you want to start coding right away. In that case, let me try another tact here. I was in your shoes too. After a long time, i can now write a program in my head and then type it up and it works perfectly first time. I mention that cause it can sound kind of impressive but it took me years of hacking away in order to do that. However, if you read that book you will be doing the same thing in months not years (and that feat will not sound impressive to you either because you will be able to do it too)!

Posted
*blink-blink* *gack* no (I dont even want to see anything like that...it sounds horrible!). Please, trust me there can not be a `Make_lsp.lsp' that you would want. Something like that would be an abomination of programing and only hurt you.

 

Amen to that :P

Posted

I understand. Thank you for your help. Though it is not that I want to begin writing lisp's immediately it is more that I feel I could learn more kinda "hands on" at least now, at the bottom, I could start with something I actually understand. I know were you are coming from, I could write a CNC program that would Blow your mind!...But only because I read the manual about 20-30 times straight through! I am not trying to be disrespectful or disregard your suggestions, but I feel that when I have an actual program I am working on, where I can test and see the results of some new variable I just read about in the book, that I would learn it better.

Posted

No i understand completely and non taken at all! ...there are tons of programs lying around you can study from. Pick your subject.

Posted

I have another question, I know, I know, but real quick.....

I am writing my first lisp and practicing the lines of code at the command line. For some reason I can not assign a decimal to a variable, for example

(setq ol1 (/ 1 2)) ; or (setq ol1 (= .5))

What am U doing wrong?

 

Also If I try to execute a (setq sd1 (getdist "\nSHOULDER DIAMETER: ")

The command line turns into something that looks like this (_> and I can't get it to go away unless I click on a tool bar feature such as "line"....

Posted

If you supply divide with two integers, then it will return an integer :)

 

Hence you will need to supply it with a REAL:

 

(setq ol1 (/ 1.0 2.0))

 

or

 

(setq ol1 (/ 1. 2.))

 

or

 

(setq ol1 0.5)

Posted
Also If I try to execute a (setq sd1 (getdist "\nSHOULDER DIAMETER: ")

The command line turns into something that looks like this (_> and I can't get it to go away unless I click on a tool bar feature such as "line"....

 

That means that you have missed a ")".

 

should be:

 

(setq sd1 (getdist "\nShoulder Diameter: "))

 

Your parenthesis need to be matched :)

Posted

If you use the Visual LISP Editor to write your code, it will automatically detect if your parenthesis are missing when you click the "Format" button.

Posted

Ok, thank you for that! That format button will come in handy! Thanks again.

Posted

One more?

 

Why does this produce an error after I answer the prompts, that says "2d point or option required" here is the code I have so far;

(defun c:gage ()

(setq sd1 (getdist "\nSHOULDER DIAMETER: ")

gd2 (getdist "\nGAGE DIAMETER: ")

gr1 (getdist "\nGAGE RADIUS: ")

ol1 (getdist "\nOver all length: ")

ul1 (getdist "\nuniform length: ")

tl1 (getdist "\nThreads length: ")

shl1 (getdist "\nshoulder length: ")

 

 

)

;Calculations

(setq sd2 (/ sd1 2.0))

 

;Program

(command "pline" "0,0,0" "0,sd2,0" "sd2,ol1,0" "ol1,0,0" "0,0,0" "")

)

I promise once I get a foundation I will stop asking questions like this but right now I am not sure were else to go to get the answer.
Posted

You are providing the command with a string, and the variables are not being evaluated (also, make sure you localise variables and use princ to exit cleanly).

(defun c:gage  (/ sd1 gd2 gr1 ol1 ul1 tl1 shl1 sd2)
 (setq sd1  (getdist "\nSHOULDER DIAMETER: ")
       gd2  (getdist "\nGAGE DIAMETER: ")
       gr1  (getdist "\nGAGE RADIUS: ")
       ol1  (getdist "\nOver all length: ")
       ul1  (getdist "\nuniform length: ")
       tl1  (getdist "\nThreads length: ")
       shl1 (getdist "\nshoulder length: ")


       )
 ;Calculations
 (setq sd2 (/ sd1 2.0))

 ;Program
 (command "pline" (list 0 0 0) (list 0 sd2 0) (list sd2 ol1 0) (list ol1 0 0) (list 0 0 0) "")
 (princ)
 )

I would look at a few tutorial sites before diving in like this. :)

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