Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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

Posted

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.

Posted

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

Posted

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

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