(defun c:test ( / *error* makepoints p1 p2 ......)
(defun C:MAIN1 ( / a)
(setq a (getint “\nNumber of items: “))
(sub1 a)
)
(defun sub1 (x) (1+ x))
(defun C:MAIN2 ( / a)
(setq a (getint "\nNumber of items: "))
(sub1 a)
)
(defun sub1 (x) (expt x 5))
(defun C:MAIN1 ( / sub1 a)
(defun sub1 (x) (1+ x))
(setq a (getint "\nNumber of items: "))
(sub1 a)
)
(defun C:MAIN2 ( / sub1 a)
(defun sub1 (x) (expt x 5))
(setq a (getint "\nNumber of items: "))
(sub1 a)
)
(defun C:CUBIC_EQ ( / func first_deriv a c b d)
(defun func (x) (apply '+ (mapcar '* (list a b c d) (list (expt x 3) (expt x 2) x 1))))
(defun first_deriv (x) (apply '+ (mapcar '* (list a b c) (list (expt x 2) x 1) (list 3 2 1))))
(setq a (getreal "\nA param: "))
(setq b (getreal "\nB param: "))
(setq c (getreal "\nC param: "))
(setq d (getreal "\nD param: "))
(list (func 10.) (first_deriv 10.))
)
If func and first_deriv were defined externally, they require more than 1 variable, something like (define func (x a b c d)… and calling them too (func x a b c d) etc.(defun C:MAIN2 ( / b)
(load "main1.lsp")
(setq b (getint "\nNumber of items: "))
(sub1 b)
)
where main1.lsp is(defun C:MAIN1 ( / a)
(setq a (getint "\nNumber of items: "))
(sub1 a)
)
(defun sub1 (x) (1+ x))
...Actually, that's what I'm trying to explain is unnecessary in AutoLisp due to the Dynamic Scoping. In your sample it would work similar even if both func & first_deriv are defined outside of C:CUBIC_EQ, exactly as they are now without the extra arguments. Of course as long as they're loaded and not overwritten by something else.
2.) Now look at this sample:Code: [Select](defun C:CUBIC_EQ ( / func first_deriv a c b d)
If func and first_deriv were defined externally, they require more than 1 variable, something like (define func (x a b c d)… and calling them too (func x a b c d) etc.
(defun func (x) (apply '+ (mapcar '* (list a b c d) (list (expt x 3) (expt x 2) x 1))))
(defun first_deriv (x) (apply '+ (mapcar '* (list a b c) (list (expt x 2) x 1) (list 3 2 1))))
(setq a (getreal "\nA param: "))
(setq b (getreal "\nB param: "))
(setq c (getreal "\nC param: "))
(setq d (getreal "\nD param: "))
(list (func 10.) (first_deriv 10.))
)
So, you can use a localized subroutine to avoid calling it with multiple arguments.
...