jbreard Posted June 18, 2012 Posted June 18, 2012 Hello everyone, I'm a total newbie with lisp and so have a total newbie's problem. I've translated an algorithm into lisp to compute the Fresnel integrals C(x) and S(x) of a given number x. The code works quite well and in the end I do have the value of C and S(x) stored in two local variables c and s. But after that, I want to use those numbers into another function. How can I tell autolisp to give me a list of c and s for example ? I tried to define another variable cs like this: (setq cs (list c s)) but then how will the programm know that I want cs for an output and not c, s or any other variable I have on the code ? I hope I've been clear enough. Thank you Jacques Quote
MSasu Posted June 18, 2012 Posted June 18, 2012 In AutoLISP the result of evaluation of last line of code is what a function will return. So, - to return the said list: (defun MyFunc() ... ;your code (setq cs (list c s)) ) - to don't return: (defun MyFunc() ... ;your code (setq cs (list c s)) (princ) ) Quote
jbreard Posted June 18, 2012 Author Posted June 18, 2012 Dear Mircea, thanks so much. I get it now. My last line was the (princ) indeed that I had copied from other lisp example without totally understanding it. I'm working on these functions to plot clothoid curves in the end. If anyone is interested out there... Regards, Jacques Quote
MSasu Posted June 18, 2012 Posted June 18, 2012 You're welcome. Please keep in mind that the PRINC/PRIN1 as last line can be legit in many cases; is usually placed as last line in function that don't need to return or in user defined command to exit quietly - that it, without a value or nil printed on command prompter. Quote
Lee Mac Posted June 18, 2012 Posted June 18, 2012 Note also that the extra 'cs' variable is not necessary: (defun YourFunction ( / c s ) (setq c 1.41421 s 1.61803 ) (list c s) ) Calling the function at the Visual LISP IDE Console: _$ (YourFunction) (1.41421 1.61803) Also, always remember to declare your local variables ('c' & 's' in the above example). Quote
jbreard Posted June 18, 2012 Author Posted June 18, 2012 Mmmm, Thanks Lee Mac. I can see that now. Much more elegant indeed ! Well, i'm moving on on my small project and write this first lisp to draw clothoid curves. I shall present it to you all very soon if I can make it work fine Regards, Jacques 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.