本帖最后由 redcat 于 2013-5-12 13:05 编辑
狂刀所说bug已修复- ;;Lisp-可选参数调用
- (defun xxcall (funclst / funs args ret tmp)
- (setq funs (car funclst)
- tmp (cdr funclst)
- )
- (if (= (type (eval funs)) 'SUBR)
- (setq ret (eval funclst))
- (while
- (and (vl-catch-all-error-p
- (setq ret (vl-catch-all-apply funs args))
- )
- (not (wcmatch
- (vl-catch-all-error-message ret)
- "参数类型错误:*"
- )
- )
- )
- (setq args (reverse (cons (car tmp) (reverse args)))
- tmp (cdr tmp)
- )
- )
- )
- ret
- )
- ;;;工程实例
- (defun tt (a b c)
- (apply '+ (list a b c))
- )
- (defun go (a b c)
- (list (if a
- a
- )
- (if b
- 51
- b
- )
- (if c
- c
- 93
- )
- )
- )
- (defun tt1 (a b c)
- (mapcar 'princ (list a b c))
- )
- (xxcall '(go nil 2))
- (xxcall '(tt 1 2 3 4))
- (xxcall '(tt 1 2))
- (xxcall '(tt1 1 2))
- (xxcall '(+ 2000 4 8))
- (xxcall '(print 2000))
- (xxcall '(princ 2000 we))
|