Save time, and automate your tasks !!!
Lesson no. 2
An AutoLisp function is always between parenthesis.So, when you open a parenthesis, you must tell what function to use, followwith the arguments when needed.(function argument1 argument2 ...)
It is very important to put the right amountof arguments to a function. Some functions have one argument, somecan have
two or more, some other can have optionalarguments.
Take, for example, the+ function. We must provide at least two arguments:(+ numbre1 numbre2 [numbre3 numbre4....])
Here, arguments in brackets [] are optionals,but the arguments "numbre1" and "numbre2" are required.
(+ 23 34) ® 57
(+ 23 34 154 -22) ®189Be careful of the spaceswhen you write a program. Sometimes you can put some spaces, some othertimes they are forbidden. So, to simplify, just follow theses two simplesrules:
1- NEVER put a space after an open parenthesis
2- ALWAYS put a space elsewhere
- With the mathematical functions, the result canbe an integer or a real. If the formula includes only integer, the resultwill be an integer. But, you need only one real in the formula to havea real for result. Be careful, this can be tricky.
(+ 23 34) ® 57®integer
(+ 23 34.0) ® 57.0®real
(/ 3 4) ® 0 ®integer(see the false result)
(/ 3 4.0) ® 0.75®real(ahhh!! thats better)You can try this in the command prompt area
COMMAND: (+ 23 34)
57
COMMAND:This is a list of the mathematical functions:
FUNCTION SYNTAXE EXAMPLE RESULT ADD (+N1 N2 ...) (+ 2 4) 2 + 4 = 6 SUBTRACT (- N1 N2 ...) (- 10 2 3) (10 - 2) - 3 = 5 MULTIPLY (* N1 N2 ...) (* 3.0 8) 3.0 * 8 = 24.0 DIVIDE (/ N1 N2 ...) (/ 48 8 3) (48 ¸ 8) ¸3 = 2 REMAIN (REM N1 N2 ...) (REM 10 3) (10 ¸ 3) = 3 RESTE 1 SQUARE ROOT (SQRTN1) (SQRT 9) Ö 9 = 3 ABSOLUTE VALUE (ABSN1) (ABS -2.5) | -2.5 | = 2.5 EXPONENTIAL (EXPN1) (EXP 2) e² = 7.38906 X TO THE Y POWER (EXPTN1 N2) (EXPT 4 3) 4³ = 64 NATURAL LOG (LOGN1) (LOG 7.38906) Ln 7.38906 = 2.71828 GREATER COMMON DENOMINATOR (GCDN1 N2) (GCD 25 30) 5 SINUS (SIN N1) (SIN 1.5708) SINUS ( ¶ ¸ 2) = 1.0 COSINUS (COSN1) (COS 0) COSINUS 0 = 1.0 ARC TANGENT (ATANN1 [N2]) (ATAN 1.0) 0.785398 For the 3 last functions, the arguments mustbe in radians. A constant exist....PI = 3.14159....Ex: (* 2 pi) ®6.28319
- Dont forget that we can nest functions....
( 8 + 4 ) / ( 5 - 2) = 4 in Lisp would be ® (/ (+ 8 4 ) (- 5 2 ))We solve the more nested parenthesis first
(+ 8 4) ® 12
(- 5 2) ® 3
(/ 12 3) ® 4