明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: nonsmall

[【不死猫】] [原创]LISP定义可选参数函数的调用

    [复制链接]
发表于 2013-5-12 13:04 | 显示全部楼层
本帖最后由 redcat 于 2013-5-12 13:05 编辑

狂刀所说bug已修复
  1. ;;Lisp-可选参数调用
  2. (defun xxcall (funclst / funs args ret tmp)
  3.   (setq  funs (car funclst)
  4.   tmp  (cdr funclst)
  5.   )
  6.   (if (= (type (eval funs)) 'SUBR)
  7.     (setq ret (eval funclst))
  8.     (while
  9.       (and (vl-catch-all-error-p
  10.        (setq ret (vl-catch-all-apply funs args))
  11.      )
  12.      (not  (wcmatch
  13.       (vl-catch-all-error-message ret)
  14.       "参数类型错误:*"
  15.     )
  16.      )
  17.       )
  18.        (setq args (reverse (cons (car tmp) (reverse args)))
  19.        tmp  (cdr tmp)
  20.        )
  21.     )
  22.   )
  23.   ret
  24. )

  25. ;;;工程实例
  26. (defun tt (a b c)
  27.   (apply '+ (list a b c))
  28. )
  29. (defun go (a b c)
  30.   (list (if a
  31.    a
  32. )
  33. (if b
  34.    51
  35.    b
  36. )
  37. (if c
  38.    c
  39.    93
  40. )
  41.   )
  42. )
  43. (defun tt1 (a b c)
  44.   (mapcar 'princ (list a b c))
  45. )
  46. (xxcall '(go nil 2))
  47. (xxcall '(tt 1 2 3 4))
  48. (xxcall '(tt 1 2))
  49. (xxcall '(tt1 1 2))
  50. (xxcall '(+ 2000 4 8))
  51. (xxcall '(print 2000))
  52. (xxcall '(princ 2000 we))

点评

mark  发表于 2017-1-24 22:29
发表于 2016-7-19 07:56 | 显示全部楼层
一样不完美,(xxcall '(tt 1 2))就是死循环
发表于 2016-10-18 15:35 | 显示全部楼层
这个帖子很多年了,其实很好的思路,作为其他功能借鉴参考
发表于 2021-1-7 18:17 | 显示全部楼层
很好很好!学习一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-9 06:56 , Processed in 0.564310 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表