本帖最后由 gaics 于 2021-8-20 07:34 编辑
 - (defun c:tt1 ()
- (defun Subfunction ()
- (princ "a")
- )
- (Subfunction)
- (princ)
- );;tt1返回a
- (defun c:tt2 (/ Subfunction)
- (defun Subfunction ()
- (princ "b")
- )
- (Subfunction)
- (princ)
- );;tt2返回b
- (defun c:tt3 ()
- (Subfunction)
- (defun bcd ()
- (princ "c")
- )
- (princ)
- );;tt3返回a或c或e
- (defun c:tt4 (/ Subfunction)
- (Subfunction)
- (defun Subfunction ()
- (princ "d")
- )
- (princ)
- );;tt4返回; 错误: no function definition: Subfunction
- (defun Subfunction ()
- (princ "e")
- )
如上面的代码定义了5个同名子函数,tt1~4分别做不同的调用写法,返回不同的结果。
tt3返回值具有不确定性,取决于tt1、tt2以及放置在主函数外面的Subfunction哪个被最近调用过。
综上,推荐tt2的写法,既不怕子函数重名,而且对其他函数也没有影响。
各位,是否可以这么理解?
|