像这样的?
- (defun C:SpaghettiCode ( / a b c a1 b1 c1 sub1 sub2 ) ; localise everything
-
- ;; declare some variables in our main function:
- (mapcar 'set '(a b c) '(1 "this is b" t))
-
- ;; declare a subfunction that expects three variables, and asigns global symbols 'a1', 'b1' and 'c1'
- (defun sub1 ( a b c )
- (setq a1 (* a 2))
- (setq b1 (strcat "yes, " b))
- (setq c1 (if c :vlax-true :vlax-false))
- )
-
- ;; declare a subfunction that uses the above global symbols 'a1', 'b1' and 'c1'
- (defun sub2 nil
- (alert
- (strcat
- "\n'a1' is: " (itoa a1)
- "\n'b1' is: '" b1 "'"
- "\n'c1' is: '" (vl-prin1-to-string c1) "'"
- )
- )
- )
-
- ;; Run the subfunctions:
- (sub1 a b c) ;; this will bound values to the symbols 'a1', 'b1' and 'c1'
- (sub2) ;; this will use the symbols 'a1', 'b1' and 'c1'
-
- (princ)
- )
|