Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Value from outside program

wstowe
Advocate
Advocate

Value from outside program

wstowe
Advocate
Advocate

Hello,

 

I have been going through tutorials on AlfraLISP.com. Very helpful site for beginners and I'm sure advanced users too.

 

"(defun drawline (a / pntl pnt2)
The last, variable a receives the first value to it from outside the program."

 

This statement is a direct quote from AlfraLISP.com.

https://www.afralisp.net/autolisp/tutorials/quick-start.php

By Kenny Ramage

 

My question is as follows. When it says "outside the program", does that mean from another document? Such as another .lsp file or excel file or can that mean from within the same .lsp file but in a seperate section/command/function?(I don't have the LSIP jargon down yet so not sure how to word that last part)

0 Likes
Reply
Accepted solutions (1)
784 Views
5 Replies
Replies (5)

jonathanhandojo
Contributor
Contributor

a is the argument the function "drawline" accepts. In that case, drawline only accepts one argument a. 

 

As an example:

 

(defun addbyfive (a)

  (+ a 5)

  )

 

When you want to call the addbyfive function, you call it by doing:

 

(addbyfive 10) 

 

and the function will return 15.

0 Likes

devitg
Advisor
Advisor

erased

0 Likes

wstowe
Advocate
Advocate

I may not have worded my question well. My apologies.

 

I'm not trying to do anything specific but to understand general LISP rules and how it works.

 

Here is another example of what I'm trying to understand from AfraLISP.com.

 

The third option is to list a variable without the /.
This means that a variable is set up to receive a value passed to it from outside the program. eg :

	(defun DTR (a)
	   

          (* PI (/a 180.0))
	)

 

So it's looking for the "a" outside the program?

The "/" needs to be in front of the character?

 

0 Likes

jonathanhandojo
Contributor
Contributor

No, a is basically a variable that you use to substitute your argument inside the function. If you don't provide a number to x in (DTR x), then your function will return an error.

 

Instead of (defun DTR (a) (* pi (/ a 180.0))), it can also be (defun DTR (abcdef) (* pi (/ abcdef 180.0))). It means the same thing.

 

So it can be (DTR 180), so that means a = 180

then on running (* pi (/ a 180.0)), AutoLISP will calculate (* pi (/ 180 180)), giving you a result of pi.

0 Likes

Kent1Cooper
Consultant
Consultant
Accepted solution

@wstowe wrote:

....

The third option is to list a variable without the /.

This means that a variable is set up to receive a value passed to it from outside the program. eg :

	(defun DTR (a)
          (* PI (/a 180.0))
	)

....

 


[That needs a space between the / and the  a  -- there is no function called  /a .]

 

I would word that differently.  In this case,  a  is an argument, which is not really the same kind of thing as a variable.  An argument must be fed in when the function is used; a localized variable is internal to the function's operations.  The difference is the reason for the slash [if used] in the parentheses after the function name:

(defun WHATEVER (arguments if any go here / localized variables if any go here) ....

 

If there are no localized variables, that slash is not needed [as is the case with that (DTR) function].  If there are, but there are no arguments to be fed in, the slash is  needed:

 

(defun WHATEVER (/ localized variables if any go here) ....

 

and that is typical of Command definitions beginning with  (defun C:MickeyMouse (/ variables) ....  which are not supposed to have arguments.

 

If a function definition lists an argument, you must feed in a value for it inside the parentheses when the function is called, in that case:

 

(dtr 45)

 

and the 45 will be used inside the routine wherever the argument  a  appears.  Such function definitions can call for more than one argument -- you must supply a value for each in the order in which they are listed in the definition.

 

Kent Cooper, AIA
0 Likes