TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CatDance on January 11, 2022, 01:13:06 AM
-
example ..
(while (SignOf
<and
> angle 90) ;eg (while (< 45 90) .... then do stuff
);while
);defun
SignOf<and> is a var of < or > depending on what I set it before going into this subr to do stuff
Example (Subr_A < 45)
-
Hi,
With LISP (as with other functional programming (https://www.tutorialspoint.com/functional_programming/functional_programming_introduction.htm) laguages) functions are treated as first-class citizens (https://en.wikipedia.org/wiki/First-class_citizen). That means functions can be used the same way as other data type, e.g. stored in variables, passed as arguments to other functions, returned by functions.
In you case, you can directly pass the < or > operator to the subr_A function:
or store it in a variable before:
But, to be consistent with native higher order functions, you should quote the function passed as argument.
(defun subr_A
(SignOf
<and
> ang
) .... then do stuff
)
)
Then you can call it with the quoted operator
or store it in a variable before:
NOTA: you should not use 'angle' as variable name. It is a protected symbol (native function).
-
Another way of defining your 'subr_A' function so that it can accept either quoted or non-quoted operator:
(defun subr_A
(SignOf
<and
> ang
) (while (SignOf
<and
> ang
90) .... then do stuff
)
)